Before adding IP, we need to prepare the following information. Please pay attention to replacing the corresponding parameters in angle brackets.
CentOS 6
1. Set a static IP.
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Copy after login
Change BOOTPROTO=dhcp to BOOTPROTO=static, and add the IP address, subnet mask and default gateway at the end of the file. This information can be obtained in the cloud server management.
BOOTPROTO=static
...
IPADDR=<currentip>
NETMASK=<netmask>
GATEWAY=<gateway>
DNS1=<dns1>
Copy after login
2. Create a network interface configuration file.
vi /etc/sysconfig/network-scripts/ifcfg-eth0:1
Copy after login
The content is as follows:
DEVICE=eth0:1
BOOTPROTO=static
IPADDR=<newip>
NETMASK=<netmask>
ONBOOT=yes
Copy after login
3. Activate the network interface and the IP address is added.
ifup eth0:1
Copy after login
Ubuntu
1. Check the network device name, such as eth0.
ip link show
Copy after login
Copy after login
2. Edit the network interface configuration file.
vi /etc/network/interfaces
Copy after login
Copy after login
The content is as follows:
auto eth0:0
iface eth0:0 inet static
address <newip>
netmask <netmask>
Copy after login
3. Activate the network interface and the IP address is added.
ifup eth0:0
Copy after login
Ubuntu 16.x
1. Check the network device name, such as ens3.
ip link show
Copy after login
Copy after login
2. Edit the network interface configuration file.
vi /etc/network/interfaces
Copy after login
Copy after login
The content is as follows:
auto ens3:0
iface ens3:0 inet static
address <newip>
netmask <netmask>
Copy after login
3. Activate the network interface and the IP address is added.
ifup ens3:0
Copy after login
FreeBSD 10
1. Edit the network interface configuration file.
vi /etc/rc.conf
Copy after login
The content is as follows:
ifconfig_vtnet0_alias0="<newip> netmask <netmask>"
Copy after login
2. Execute the following command to restart the network.
/etc/rc.d/netif restart && /etc/rc.d/routing restart
Copy after login
The above is the detailed content of How to add IP address to Linux cloud server. For more information, please follow other related articles on the PHP Chinese website!