How to Add an IP Address to a Server
Adding an IP address to a server can be useful for many reasons such as hosting multiple websites, creating a separate network, or running specific applications that require a dedicated IP address. Here are the steps to add an IP address to a server:
1. Log in to the server: Log in to the server using SSH or any other method.
2. Check the current network configuration: Use the `ifconfig` command to check the current network configuration of the server. This command will show you all the active network interfaces and their IP addresses.
3. Determine the interface name: Determine the name of the network interface that you want to add an IP address to. Typically, this is "eth0" or "ens160".
4. Edit the network configuration file: Navigate to the network configuration file of your server. In Ubuntu or Debian, this is usually located at `/etc/network/interfaces`. In CentOS or RHEL, it is located at `/etc/sysconfig/network-scripts/ifcfg-eth0`. Open this file in a text editor and add the following lines at the end:
``` auto eth0:1 iface eth0:1 inet static address <new IP address> netmask <subnet mask> ```
Replace `eth0` with the name of the interface and `<new IP address>` and `<subnet mask>` with the IP address and subnet mask that you want to add.
5. Save and close the file: Save and close the network configuration file.
6. Restart the network interface: Restart the network interface to apply the changes. Use the following command:
``` sudo ifdown eth0:1 && sudo ifup eth0:1 ```
This will bring down the network interface and then bring it back up with the new IP address.
7. Verify the new IP address: Use the `ifconfig` command again to verify that the new IP address has been added to the network interface.
That's it! You have successfully added an IP address to your server.