① 开机启动树莓派。
② 备份网络接口配置文件,卸载自带的dhcpcd5程序,命令如下:
1:su
2:cp /etc/network/interfaces /etc/network/interfacesbackup 3:apt-get purge dhcpcd5
4:cp /etc/network/interfacesbackup /etc/network/interfaces
5: 重启树莓派
③ 编辑网络接口配置文件(/etc/network/interfaces)
1:改动eth0的配置,就是树莓派自带网口的配置。
原文件有关网口eth0的配置内容如下: auto eth0
allow-hotplug eth0 iface eth0 inet manual
将上面这几行改为:
auto eth0
allow-hotplug eth0 iface eth0 inet static
address 192.168.1.51 netmask 255.255.255.0 gateway 192.168.1.1
dns-nameservers 221.228.255.1 #dns地址,只需要在对外网的eth中配置 dns-nameservers 8.8.8.8 #dns备用地址
2:如果装有usb转RJ45设备,那么按照上面的eth0方式增加或修改对网口eth1、eth2...ethx的配置即可。
例如:一个树莓派自带网口,两个usb转RJ45设备,配置成三个网段: auto eth0
allow-hotplug eth0 iface eth0 inet static address 192.168.1.51 netmask 255.255.255.0 gateway 192.168.1.1
dns-nameservers 221.228.255.1 #dns地址,只需要在对外网的eth中配置 dns-nameservers 8.8.8.8 #dns备用地址
auto eth1
iface eth1 inet static address 192.168.2.2 netmask 255.255.255.0 gateway 192.168.2.1
auto eth2
iface eth2 inet static address 192.168.3.3 netmask 255.255.255.0 gateway 192.168.3.1
④ 重启树莓派即可。
相关推荐: