To assign a secondary IP address to a network interface, the method can vary depending on the operating system. Here are examples for both Linux and Windows:
On Linux
Using the
ipcommand:sudo ip addr add <secondary_ip_address>/<subnet_mask> dev <interface_name>Example:
sudo ip addr add 192.168.1.10/24 dev eth0Using the
ifconfigcommand (deprecated in some distributions):sudo ifconfig <interface_name> <secondary_ip_address> netmask <subnet_mask> upExample:
sudo ifconfig eth0:0 192.168.1.10 netmask 255.255.255.0 upPersistent Configuration: To make the change persistent across reboots, you can edit the network configuration files, typically found in
/etc/network/interfacesor/etc/sysconfig/network-scripts/ifcfg-<interface_name>depending on your distribution.
On Windows
Using Command Prompt: Open Command Prompt as Administrator and run:
netsh interface ip add address "<interface_name>" <secondary_ip_address> <subnet_mask>Example:
netsh interface ip add address "Ethernet" 192.168.1.10 255.255.255.0Using GUI:
- Go to Control Panel > Network and Sharing Center > Change adapter settings.
- Right-click on the network interface and select Properties.
- Select "Internet Protocol Version 4 (TCP/IPv4)" and click Properties.
- Click on "Advanced" and then under the "IP Addresses" section, click "Add" to enter the secondary IP address.
Note
Make sure to replace <secondary_ip_address>, <subnet_mask>, and <interface_name> with the appropriate values for your network configuration.
