使用 putty 链接到树莓派
- 首先请安装 Putty 下载地址 https://www.chiark.greenend.org.uk/~sgtatham/putty/
2. 网线连接路由器和树莓派
3. 打开路由器页面找到树莓派的IP:
我这里路由器的IP是:192.168.1.1,所以在浏览器网址中输入:http://192.168.1.1/
找到路由器的IP地址是:192.168.1.100
4. 打开 Putty 选择SSH 输入 IP地址和端口号码
注意IP地址要换成我们上面找到的:192.168.1.100
然后输入用户名和密码
-
弹出警告窗点击 Yes
5 查看当前的IP情况.
pi@raspberrypi:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.150 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::f3d6:e61a:4113:eb2f prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:a2:9b:5d txqueuelen 1000 (Ethernet)
RX packets 9059 bytes 593346 (579.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 702 bytes 107606 (105.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 564 bytes 55357 (54.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 564 bytes 55357 (54.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::ac2b:a401:95d:c223 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:f7:ce:08 txqueuelen 1000 (Ethernet)
RX packets 1601 bytes 101253 (98.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1961 bytes 287312 (280.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
pi@raspberrypi:~ $
注意上图中我们可以看到有两个网卡:
eth0:192.168.0.150
wlan0:192.168.0.100
所以我们实际联网情况是这样的:
6 查看当前的IP情况
打开网络配置文件
pi@raspberrypi:~ $ sudo nano /etc/dhcpcd.conf
修改网络配置文件
7 重启网络.
sudo ifconfig eth0 down
sudo ifconfig eth0 up
------------------------------------------------------------------------
pi@raspberrypi:~ $ sudo ifconfig eth0 down
pi@raspberrypi:~ $ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 761 bytes 74050 (72.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 761 bytes 74050 (72.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::ac2b:a401:95d:c223 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:f7:ce:08 txqueuelen 1000 (Ethernet)
RX packets 2851 bytes 200735 (196.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3462 bytes 521712 (509.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
------------------------------------------------------------------------
pi@raspberrypi:~ $ sudo ifconfig eth0 up
pi@raspberrypi:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.114.204.195 netmask 255.255.255.0 broadcast 10.114.204.255
inet6 fe80::f3d6:e61a:4113:eb2f prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:a2:9b:5d txqueuelen 1000 (Ethernet)
RX packets 18524 bytes 3875246 (3.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2314 bytes 277219 (270.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 766 bytes 74575 (72.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 766 bytes 74575 (72.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::ac2b:a401:95d:c223 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:f7:ce:08 txqueuelen 1000 (Ethernet)
RX packets 2939 bytes 210566 (205.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3529 bytes 535998 (523.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
pi@raspberrypi:~ $
注意eth0 的IP已经更改为:10.114.204.195
8 手动临时修改IP地址.
ifconfig eth0 192.168.1.4 netmask 255.255.255.0
ifconfig eth0 down
ifconfig eth0 up
9 命令总结.
ifconfig
sudo ifconfig eth0 down
sudo ifconfig eth0 up
sudo nano /etc/dhcpcd.conf
动态IP:
iface eth0 inet dhcp
静态IP:
interface eth0
static ip_address=192.168.0.150
static routers=192.168.0.1