在Ubuntu服务器中,我在/ etc / network / interfaces文件中configuration了eth0:1
# The primary network interface auto eth0 iface eth0 inet static address 192.168.1.111 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 8.8.8.8 dns-search defaultdomain iface eth0:1 inet static address 192.168.4.1 netmask 255.255.255.0
我可以看到它使用ifconfig:
eth0:1 Link encap:Ethernet HWaddr 52:54:00:a9:7c:83 inet addr:192.168.4.1 Bcast:192.168.4.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
但是我发现另一种方法,就是使用eth0两次。
# The primary network interface auto eth0 iface eth0 inet static address 192.168.1.111 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 8.8.8.8 dns-search defaultdomain iface eth0 inet static address 192.168.4.1 netmask 255.255.255.0
这次我不能通过使用ifconfig来查看192.168.4.1,但ping这个IP地址还是可以的。 以上两种方式有什么区别?
忘了我的评论,在第一种情况下,你有一个虚拟接口别名ifconfig eth0:1 192.168.4.1/24起来,在第二种情况下,你有一个辅助ip地址ip addr add 192.168.4.1/24 dev eth0
但是在这两种情况下都是次要地址,第一种是旧式,第二种是使用ip命令的新configuration样式