在添加ip之前,我们需要准备以下信息,请注意替换尖括号中相应的参数。
现有ip地址<currentip>、子网掩码<netmask>、默认网关<gateway>
新增ip地址<newip>、子网掩码<netmask>
dns服务器<dns1>
为了使新ip生效,您需要在管理中心的云服务器管理中执行重启操作。您可以通过ping命令来检测是否添加成功。
centos 61、设置静态ip。
vi /etc/sysconfig/network-scripts/ifcfg-eth0
把bootproto=dhcp改成bootproto=static,并在该文件最后添加ip地址、子网掩码和默认网关,这些信息可以在云服务器管理中获取。
bootproto=static...ipaddr=<currentip>netmask=<netmask>gateway=<gateway>dns1=<dns1>
2、创建网络接口配置文件。
vi /etc/sysconfig/network-scripts/ifcfg-eth0:1
内容如下:
device=eth0:1bootproto=staticipaddr=<newip>netmask=<netmask>onboot=yes
3、激活网络接口,ip地址添加完毕。
ifup eth0:1
ubuntu1、查看网络设备名称,比如eth0。
ip link show
2、编辑网络接口配置文件。
vi /etc/network/interfaces
内容如下:
auto eth0:0iface eth0:0 inet staticaddress <newip>netmask <netmask>
3、激活网络接口,ip地址添加完毕。
ifup eth0:0
ubuntu 16.x1、查看网络设备名称,比如ens3。
ip link show
2、编辑网络接口配置文件。
vi /etc/network/interfaces
内容如下:
auto ens3:0iface ens3:0 inet staticaddress <newip>netmask <netmask>
3、激活网络接口,ip地址添加完毕。
ifup ens3:0
freebsd 101、编辑网络接口配置文件。
vi /etc/rc.conf
内容如下:
ifconfig_vtnet0_alias0=<newip> netmask <netmask>
2、执行以下命令重启网络。
/etc/rc.d/netif restart && /etc/rc.d/routing restart
以上就是linux云服务器怎么添加ip地址的详细内容。