树莓派配置静态ip和动态DHCP获取ip

1  配置DHCP动态获取ip:
开启dhcpcd服务
pi@pi_new:~ $ !718
sudo vi /etc/network/interfaces
pi@pi_new:~ $ sudo systemctl enable dhcpcd 
Synchronizing state of dhcpcd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable dhcpcd
pi@pi_new:~ $ 
pi@pi_new:~ $ date 
Sun 4 Aug 10:05:55 HKT 2019
编辑/etc/network/interfaces,修改有线网卡获取ip方式为dhcp,
pi@pi_new:~ $ sudo tail -30 /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
 
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
 
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
 
auto enxb827eb873f7f
iface enxb827eb873f7f inet dhcp
#iface enxb827eb873f7f inet static
#address 172.17.1.111
#netmask 255.255.255.0
#network 172.17.1.0
#broadcast 172.17.1.255
#gateway 172.17.1.254
#dns-nameservers 172.17.1.140 223.5.5.5
2  配置静态ip:
关闭dhcpcd服务,
pi@pi_new:~ $ date ; sudo systemctl disable dhcpcd 
Sun 4 Aug 10:08:23 HKT 2019
Synchronizing state of dhcpcd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable dhcpcd
Removed /etc/systemd/system/dhcpcd5.service.
编辑/etc/network/interfaces,修改有线网卡ip信息,
pi@pi_new:~ $ sudo tail -30 /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
 
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
 
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
 
auto enxb827eb873f7f
#iface enxb827eb873f7f inet dhcp
iface enxb827eb873f7f inet static
address 172.17.1.111
netmask 255.255.255.0
network 172.17.1.0
broadcast 172.17.1.255
gateway 172.17.1.254
dns-nameservers 172.17.1.140 223.5.5.5

发表评论

电子邮件地址不会被公开。