静态IP地址配置文件路径 /etc/network/interfaces
interfaces格式
#设置单个ipv4地址
The loopback interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.9.51
netmask 255.255.252.0
gateway 192.168.9.1
mtu 1500
#设置单个ipv6地址
#The loopback interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet6 static
address 2001:f80:754::51
netmask 64
gateway 2001:f80:754::1
mtu 1500
#同时设置ipv4和ipv6地址
#The loopback interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet6 static
address 2001:f80:754::51
netmask 64
gateway 2001:f80:754::1
mtu 1500
iface eth0 inet static
address 192.168.9.58
netmask 255.255.252.0
gateway 192.168.9.1
mtu 1500
#设置多个ipv4地址
#The loopback interface
auto lo
iface lo inet loopback
auto eth0 eth0:1
iface eth0 inet6 static
address 2001:f80:754::51
netmask 64
gateway 2001:f80:754::1
mtu 1500
iface eth0 inet static
address 192.168.9.58
netmask 255.255.252.0
gateway 192.168.9.1
mtu 1500
iface eth0:1 inet static
address 192.168.9.59
netmask 255.255.252.0
gateway 192.168.9.1
mtu 1500
#注:有几个地址就配置几个接口。冒号后面的数字可以随便写的,只要几个配置的名字不重复就可以。
但是要记住重启网卡时ifup 对应的接口名字,比如ifup eth0:1
命令行添加IP地址
ifconfig eth0 add 2001:f80:754::4/64