现在,让我们来分配一个额外的地址,例如 192.168.1.104/24。
编辑 /etc/network/interfaces:
sudonano/etc/network/interfaces
如下添加额外的 IP 地址。
#Thisfile describes the network interfaces available on your system
#and how to activate them.Formore information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp
iface enp0s3 inet static
address 192.168.1.104/24
保存并关闭文件。
运行下面的命令使更改无需重启即生效。
sudo ifdown enp0s3 &&sudo ifup enp0s3
样例输出:
Killed old client process
InternetSystemsConsortium DHCP Client4.3.1
Copyright2004-2014InternetSystemsConsortium.
All rights reserved.
Forinfo, please visit https://www.isc.org/software/dhcp/
Listening on LPF/enp0s3/08:00:27:2a:03:4e
Sending on LPF/enp0s3/08:00:27:2a:03:4e
Sending on Socket/fallback
DHCPRELEASE on enp0s3 to 192.168.1.1 port 67(xid=0x225f35)
InternetSystemsConsortium DHCP Client4.3.1
Copyright2004-2014InternetSystemsConsortium.
All rights reserved.
Forinfo, please visit https://www.isc.org/software/dhcp/
Listening on LPF/enp0s3/08:00:27:2a:03:4e
Sending on LPF/enp0s3/08:00:27:2a:03:4e
Sending on Socket/fallback
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3(xid=0xdfb94764)
DHCPREQUEST of 192.168.1.103 on enp0s3 to 255.255.255.255 port 67(xid=0x6447b9df)
DHCPOFFER of 192.168.1.103from192.168.1.1
DHCPACK of 192.168.1.103from192.168.1.1
bound to 192.168.1.103-- renewal in35146 seconds.
注意:如果你从远程连接到服务器,把上面的两个命令放到一行中非常重要,因为第一个命令会断掉你的连接。而采用这种方式可以保留你的 ssh 会话。
现在,让我们用下面的命令来检查一下是否添加了新的 IP:
sudoip address show enp0s3
输出样例:
2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:2a:03:4e brd ff:ff:ff:ff:ff:ff
inet 192.168.1.103/24 brd 192.168.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet 192.168.1.104/24 brd 192.168.1.255 scope global secondary enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe2a:34e/64 scope link
valid_lft forever preferred_lft forever
很好!我们已经添加了额外的 IP。
再次 ping IP 地址进行验证。
sudoping192.168.1.104
样例输出:
PING 192.168.1.104(192.168.1.104)56(84) bytes of data.
64 bytes from192.168.1.104: icmp_seq=1 ttl=64time=0.137 ms
64 bytes from192.168.1.104: icmp_seq=2 ttl=64time=0.050 ms
64 bytes from192.168.1.104: icmp_seq=3 ttl=64time=0.054 ms
64 bytes from192.168.1.104: icmp_seq=4 ttl=64time=0.067 ms
好极了!它能正常工作。就是这样。
2015职称计算机考试书PowerPoint2007中 .. 定价:¥45 优惠价:¥42 更多书籍 | |
2015年全国职称计算机考试教材(2007模 .. 定价:¥225 优惠价:¥213 更多书籍 |