Q-Logo 我的学习笔记分享

树莓派 4B 设置wlan0使用静态IP

ifconfig 或ifconfig –a 查看网卡信息,eth0为有线网,wlan0为无线网,可以查看到两者的IP。然后route或netstat –rn查看网关信息,最后修改/etc/dhcpcd.conf设置静态IP地址。

pi@raspberrypi:~ $ ifconfig -a

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.1.104 netmask 255.255.255.0 broadcast 192.168.1.255

inet6 fe80::f0ec:2611:97a2:428 prefixlen 64 scopeid 0x20<link>

ether dc:a6:32:6d:eb:b1 txqueuelen 1000 (Ethernet)

RX packets 649 bytes 330302 (322.5 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 204 bytes 26309 (25.6 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 4 bytes 240 (240.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 4 bytes 240 (240.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.1.103 netmask 255.255.255.0 broadcast 192.168.1.255

inet6 fe80::d651:1021:ce42:c774 prefixlen 64 scopeid 0x20<link>

ether dc:a6:32:6d:eb:b2 txqueuelen 1000 (Ethernet)

RX packets 365 bytes 303119 (296.0 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 27 bytes 4475 (4.3 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

route或netstat –rn 查看网关信息,eth0为有线网,wlan0为无线网

pi@raspberrypi:~ $ route

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

default 192.168.1.1 0.0.0.0 UG 202 0 0 eth0

default 192.168.1.1 0.0.0.0 UG 303 0 0 wlan0

192.168.1.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0

192.168.1.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0

编辑配置文件增加内容增加如下内容

pi@raspberrypi:~ $ sudo nano /etc/dhcpcd.conf

interface wlan0

static ip_address=192.168.1.180/24

static routers=192.168.1.1

static domain_name_servers=192.168.1.1

修改完成后,保存,重启系统。

重启sudo reboot

上面修改的是wlan0无线网的配置。以后就可以在同一网段的其他电脑直接用固定的IP地址192.168.1.180通过ssh连接树莓派了。