联系我们
在线沟通
立即在线沟通,我们随时为您解答
电邮
发送邮件,我们将尽快回复您的问题
电话
立即拨打

 首页  知识库 > 服务器教程  >  raksmart服务器Ubuntu配置单个IP与整段IP

raksmart服务器Ubuntu配置单个IP与整段IP

2020-06-09

raksmart的朋友们,大家好,今天rak给大家说一下在我们的美国服务器Ubuntu系统怎么配置单个IP和整段IP,昨天和前天说的都是centos系统,今天就讲一下Ubuntu的操作方法。

raksmart的朋友们,大家好,今天rak给大家说一下在我们的美国服务器Ubuntu系统怎么配置单个IP和整段IP,昨天和前天说的都是centos系统,今天就讲一下Ubuntu的操作方法。

多IP不同段配置:  

多个不同IP段的 /etc/network/interfaces 配置文件的范例如下:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 8.8.8.2
netmask 255.255.255.248
gateway 8.8.8.1  要注意这里,多个不同IP段,只要1个gateway配置即可,其他IP不需要配置gateway

auto eth0:0
iface eth0:0 inet static
address 8.8.8.3
netmask 255.255.255.248

auto eth0:1
iface eth0:1 inet static
address 8.8.8.4
netmask 255.255.255.248

auto eth0:2
iface eth0:2 inet static
address 8.8.8.5
netmask 255.255.255.248

auto eth0:3
iface eth0:3 inet static
address 8.8.8.6
netmask 255.255.255.248
 
auto eth0:4
iface eth0:4 inet static
address 6.6.6.130   注意这里,虽然这是不同的IP段,但是不需要配置gateway,只需要配置netmask即可
netmask 255.255.255.224

auto eth0:5
iface eth0:5 inet static
address 6.6.6.131
netmask 255.255.255.224
 
更多ip也类似配置即可。
配置文件完成后,用命令   /etc/init.d/networking  restart 重启网络,不需要reboot重启服务器。 /etc/init.d/networking  restart 重启网络的时候,如果你的配置文件有错误,那么他会提示你。比如IP重复了,书写错误了,等等。

整段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的权限,注意网卡名称

以上就是在raksmart服务器Ubuntu系统附加单IP和多IP的方法,以后raksmart会为大家带来更多的服务器使用教程。


如果您觉得【raksmart服务器Ubuntu配置单个IP与整段IP】这篇文章有用,请分享给您的好友,谢谢!

复制链接