美国服务器Ubuntu系统配置单个IP与整段IP方法
1、多IP不同段配置:
多个不同IP段的 /etc/network/interfaces 配置文件的范例如下:# The loopback network interfaceauto loiface lo inet loopback# The primary network interfaceauto eth0iface eth0 inet staticaddress 8.8.8.2netmask 255.255.255.248gateway 8.8.8.1 要注意这里,多个不同IP段,只要1个gateway配置即可,其他IP不需要配置gatewa
auto eth0:0iface eth0:0 inet staticaddress 8.8.8.3netmask 255.255.255.248auto eth0:1iface eth0:1 inet staticaddress 8.8.8.4netmask 255.255.255.248auto eth0:2iface eth0:2 inet staticaddress 8.8.8.5netmask 255.255.255.248auto eth0:3iface eth0:3 inet staticaddress 8.8.8.6netmask 255.255.255.248 auto eth0:4iface eth0:4 inet staticaddress 6.6.6.130
注意这里,虽然这是不同的IP段,但是不需要配置gateway,只需要配置netmask即可
netmask 255.255.255.224auto eth0:5iface eth0:5 inet staticaddress 6.6.6.131netmask 255.255.255.224
2、更多ip也类似配置即可。配置文件完成后,用命令 /etc/init.d/networking restart 重启网络,不需要reboot重启服务器。 /etc/init.d/networking restart 重启网络的时候,如果你的配置文件有错误,那么他会提示你。比如IP重复了,书写错误了,等等。
3、整段IP添加:
整段IP添加使用脚本添加
脚本信息:
# !/bin/bash
for ((i=1;i<=255;i=i+1))
do
echo "auto eth0:$i">>/etc/network/interfaces
echo "iface eth0:$i inet static">>/etc/network/interfaces
# let j=$i
echo "address 192.1.1.$j">>/etc/network/interfaces
echo "netmask 255.255.255.0">>/etc/network/interfaces
echo "gateway 192.1.1.254">>/etc/network/interfaces
echo " ">>/etc/network/interfaces
done
# end
脚本修改文件解析:
i值是子网卡号
j是具体IP
该脚本从是从:1开始的
子网卡号可随意不冲突就行 ,let j=$i-9 利用这个 凑出具体IP
修改完系统中文件要给775的权限,注意网卡名称
以上就是在美国服务器Ubuntu系统附加单IP和多IP的方法,希望对大家有所帮助。