Assigning multiple IP addresses to a single device or network interface can serve various purposes and offer several benefits, depending on the specific use case. In this detailed tutorial, we will see how to assign multiple IP addresses to a single network card in various Linux operating systems.
Table of Contents
Why do We Configure Multiple IP Addresses?
Here are some reasons why we might want to assign multiple IP addresses:
- Network segmentation: Assigning multiple IP addresses allows you to segment your network into different subnets. This can enhance network security and help isolate different parts of your network from one another. For example, you might have separate IP address ranges for different departments or services within an organization.
- Hosting multiple websites or services: Web hosting providers often assign multiple IP addresses to a single server to host multiple websites or services on the same hardware. Each website or service can have its own IP address, which simplifies configuration and management.
- Testing and development: In testing and development environments, multiple IP addresses can be assigned to simulate different network conditions, test applications with various configurations, or create isolated testing environments.
- Setting caching proxy server: Assigning multiple IP addresses to a Internet caching and sharing server like Squid proxy server enables efficient Internet sharing across different network segments or subnets, allowing for customized access control and content filtering policies for each group of users.
- Network services and protocols: Some network services and protocols require multiple IP addresses. For example, if you're running a mail server, you may need multiple IP addresses for different email domains or services like IMAP, POP3, and SMTP.
In summary, configuring multiple IP addresses provides flexibility and functionality in managing networks, improving performance, enhancing security, and accommodating various network services and applications.
The specific reasons for configuring secondary IP addresses will depend on the requirements of your network or system.
Before going further, it is recommended to understand different classes and ranges in IP version 4 and CIDR.
IPv4 Address Classes
In IPv4, IP addresses are divided into five classes: A, B, C, D, and E. Each class has a specific range of IP addresses and is used for different purposes. Class A, B, and C are commonly used.
The following table provides examples of IP series for each class and their respective purposes.
Class | Range of IP Addresses | Example IP Series | Purpose |
---|---|---|---|
A | 0.0.0.0 - 127.255.255.255 | 10.0.0.0 - 10.255.255.255 | Used for large networks |
B | 128.0.0.0 - 191.255.255.255 | 172.16.0.0 - 172.31.255.255 | Used for medium-sized networks |
C | 192.0.0.0 - 223.255.255.255 | 192.168.0.0 - 192.168.255.255 | Used for small networks |
D | 224.0.0.0 - 239.255.255.255 | 232.0.0.0 - 232.255.255.255 | Reserved for multicast groups |
E | 240.0.0.0 - 255.255.255.255 | N/A (Experimental and Reserved) | Reserved for future/experimental use |
What is CIDR?
It's important to note that classful addressing has been largely replaced by Classless Inter-Domain Routing (CIDR) in modern networking, which allows for more flexible allocation of IP address ranges and subnetting.
Classless Inter-Domain Routing (CIDR) is a notation and addressing scheme introduced to overcome the limitations of the traditional class-based addressing system used in IPv4.
CIDR provides more flexibility in subnetting and allocating IP addresses, allowing for efficient utilization of address space and simplifying routing on the internet.
CIDR notation represents IP addresses in a format that includes both the IP address and the subnet mask length. It uses a forward slash ("/") followed by the number of bits in the subnet mask. For example, "192.168.1.0/24" specifies the IP address "192.168.1.0" with a subnet mask of 24 bits, indicating a subnet size of 256 addresses (2^8).
CIDR has become the standard addressing and routing method in IPv4 and is essential for efficient IP address allocation and internet routing.
It enables organizations to manage their IP address space more effectively and helps reduce the growth of the global routing table by allowing route aggregation.
Well, that's enough for this topic. Let us move to learn various methods to configure a secondary IP address in Linux.
1. Assign Multiple Addresses to a Single Network Interface in Linux via Netplan Configuration File
Netplan is commonly used in modern Linux distributions like Ubuntu for configuring network settings.
1. Identify the Network Interface:
Use the ip a
or ip link
command to list your network interfaces. Note the name of the interface you want to configure, e.g., eth0
or ens18
.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether 6e:26:0b:8e:33:8c brd ff:ff:ff:ff:ff:ff
In this example, we'll assume you want to add two additional IP addresses to the existing network interface named "ens18."
2. Create or Edit a Netplan Configuration File:
You typically find Netplan configuration files in the /etc/netplan/
directory. These files have a .yaml
extension.
You can create a new configuration file or edit an existing one.
For example, let's edit the default Netplan configuration file, which is often named something like 01-netcfg.yaml
or 50-cloud-init.yaml
:
$ sudo nano /etc/netplan/01-netcfg.yaml
3. Configure the Network Interface:
In the configuration file, specify the network interface (ens18
in this case) and add the additional IP addresses using the "addresses" key.
network: version: 2 renderer: networkd ethernets: ens18: dhcp4: no addresses: - 192.168.1.22/24 - 192.168.1.23/24 - 192.168.1.24/24 routes: - to: default via: 192.168.1.101 nameservers: addresses: [8.8.8.8, 8.8.4.4]
In this example, we've added three IP addresses (192.168.1.22, 192.168.1.23, and 192.168.1.24) to the "ens18" interface. Replace the IP addresses, subnet masks, gateway, and DNS servers with your specific network configuration.
Press CTRL+O
followed by CTRL+X
to save the file and close it.
4. Validate Configuration File:
Please be mindful that Netplan uses YAML (Yet Another Markup Language) for its configuration syntax, and YAML is highly sensitive to whitespace and indentation.
Incorrect indentation can lead to errors or misconfigurations. A common practice is to use spaces (typically 2 or 4) for indentation rather than tabs to maintain consistency.
When editing a Netplan configuration file:
- Be consistent with the number of spaces you use for indentation at each level.
- Avoid using tabs. If you're using an editor like
nano
, you can configure it to replace tabs with spaces for consistency.
Before applying any changes, always validate the configuration using the command:
$ sudo netplan try
This command allows you to test the configuration, and if there's an error, it will revert to the previous working configuration after a timeout.
5. Apply the Configuration:
After saving your changes to the Netplan configuration file, apply the configuration by running:
$ sudo netplan apply
6. Verify the Configuration:
To confirm that the additional IP addresses have been assigned to the network interface, you can use the ip addr
command:
$ ip addr show ens18
This command should display the network interface with the added IP addresses.
2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 6e:26:0b:8e:33:8c brd ff:ff:ff:ff:ff:ff altname enp0s18 inet 192.168.1.22/24 brd 192.168.1.255 scope global ens18 valid_lft forever preferred_lft forever inet 192.168.1.23/24 brd 192.168.1.255 scope global secondary ens18 valid_lft forever preferred_lft forever inet 192.168.1.24/24 brd 192.168.1.255 scope global secondary ens18 valid_lft forever preferred_lft forever
That's it! You have successfully assigned multiple IP addresses to a network interface using Netplan in Linux. Make sure to adjust the configuration to match your specific network requirements and naming conventions.
You can verify if all IPs are working by pinging them.
$ ping -c 3 192.168.1.22
$ ping -c 3 192.168.1.23
$ ping -c 3 192.168.1.24
2. Configure Multiple IP Addresses using nmcli Command
nmcli
is a command-line tool for managing NetworkManager, which is commonly used for network configuration on Linux systems.
To assign multiple IP addresses to a network interface using the nmcli
command in Linux, you can follow these steps.
1. List Network Connections:
Use the following command to list the available network connections managed by NetworkManager:
$ nmcli connection show
Identify the network connection you want to configure with multiple IP addresses. Note the name of the connection; it is often named something like 'Wired connection 1", "eth0" or "ens18."
2. Add Additional IP Addresses:
You can add multiple IP addresses to the chosen network connection using the nmcli
command. Replace connection-name
with the name of your network connection.
$ sudo nmcli connection modify 'Wired connection 1' +ipv4.addresses "192.168.1.22/24,192.168.1.23/24,192.168.1.24/24"
In the command above, we are adding three IP addresses (192.168.1.22, 192.168.1.23, and 192.168.1.24) with a subnet mask of /24 to the specified network connection.
3. Apply the Changes:
Apply the changes to the network configuration by restarting the network connection:
$ sudo nmcli connection down 'Wired connection 1' $ sudo nmcli connection up 'Wired connection 1'
Replace connection-name
with the name of your network connection.
4. Verify the Configuration:
To confirm that the additional IP addresses have been assigned to the network interface, you can use the ip addr
or nmcli connection show
command:
$ nmcli con show 'Wired connection 1'
This command should display the network interface with the added IP addresses.
Your network connection should now have multiple IP addresses assigned to it using nmcli
. Make sure to adjust the configuration to match your specific network requirements and the name of your network connection.
3. Set Multiple IP Addresses using nmtui Utility
The nmtui
is a terminal-based user interface tool that allows you to manage network configurations on systems using NetworkManager.
1. Install nmtui (if not already installed):
Depending on your Linux installation, nmtui
might not be installed by default. You can install it using the following commands:
$ sudo apt update $ sudo apt install network-manager
2. Launch nmtui:
Simply type the command: $ sudo nmtui
3. Navigate the nmtui menu:
Use the arrow keys to navigate and the Enter key to make selections. Highlight the "Edit a connection" option and press Enter.
From the list of connections, use arrow keys to highlight the connection for which you want to set a static IP, then press TAB key to choose "Edit" and press Enter.
Enter your network settings such as IP address, Gateway, DNS etc.
- Navigate to the "IPv4 CONFIGURATION" section.
- Change the "Automatic" option (which indicates DHCP) to "Manual" using the arrow keys and space bar.
- Below the "Addresses" section, press Enter to add a new address. Here, input all static IP addresses and subnet mask. For example:
192.168.1.22/24
,192.168.1.23/24
,192.168.1.24/24
, and192.168.1.25/24
etc. - Set the gateway in the "Gateway" field.
- In the "DNS servers" section, input your desired DNS servers, separated by semicolons (
;
). For example, to use Google's DNS:8.8.8.8;8.8.4.4
.
After filling in all the details, navigate to the "OK" option at the bottom and press Enter.
Finally, navigate to "Back" and then "Quit" to exit nmtui
.
4. Restart NetworkManager:
To apply the changes, you might need to restart the NetworkManager service:
$ sudo systemctl restart NetworkManager
And that's it! You've now configured multiple static IP addresses on your Linux machine using nmtui
.
Finally, verify IP address using ip a
command.
The above 3 methods are standard and have been commonly used in modern Linux systems. If you're using older Linux distributions like Ubuntu 16.04 or CentOS 7, the following methods will help you to configure secondary IP addresses.
4. Configure Multiple IP Addresses using ip Command in Older DEB-based Systems
The following steps are tested on a Ubuntu 16.04 LTS server edition. However, this will work on Debian and other DEB based systems such as Linux Mint, Pop!_OS, Elementary OS etc.
As you may know already, we can find the IP address in Ubuntu using command:
$ ip addr
Sample output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:12:f8:c1 brd ff:ff:ff:ff:ff:ff inet 192.168.1.105/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe12:f8c1/64 scope link valid_lft forever preferred_lft forever
In older systems, you can use the following command instead:
$ ifconfig
As you see above, the IP address of my network card enp0s3 is 192.168.1.105.
It is obvious that I have assigned class C type IP series i.e 192.168.1.0 to my network card. What If I need to assign an additional IP series, for example 192.168.2.0?
Just run the following command to set an extra IP.
$ sudo ip addr add 192.168.2.105/24 dev enp0s3
Here, 24 indicates the netmask i.e 255.255.255.0.
Now, let us check if the new IP is assigned using command:
$ ip addr
Sample output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:12:f8:c1 brd ff:ff:ff:ff:ff:ff inet 192.168.1.105/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 192.168.2.105/24 scope global enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe12:f8c1/64 scope link valid_lft forever preferred_lft forever
As you see in the above output, my network card has now two IPs i.e 192.168.1.105 and 192.168.2.105. Similarly, you can assign as many additional IPs as you like i.e 192.168.3.105, 192.168.4.105 etc.
Let us ping the new IP address:
$ ping -c 3 192.168.2.105
Sample output:
PING 192.168.2.105 (192.168.2.105) 56(84) bytes of data. 64 bytes from 192.168.2.105: icmp_seq=1 ttl=64 time=0.040 ms 64 bytes from 192.168.2.105: icmp_seq=2 ttl=64 time=0.067 ms 64 bytes from 192.168.2.105: icmp_seq=3 ttl=64 time=0.066 ms --- 192.168.2.105 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.040/0.057/0.067/0.015 ms
Congratulations! It's working!!
Wait, we haven't finished yet. What we have done so far is we only assigned the new IP temporarily. After system reboot, the newly assigned IP will be gone. How do you make it permanently? It's simple too.
4.1. Assign Multiple IP Addresses Permanently
Edit /etc/network/interfaces file:
$ sudo nano /etc/network/interfaces
Now, add the additional IP address as shown below:
iface enp0s3 inet static address 192.168.2.105/24
Save and close the file.
Run the following command to take effect the saved changes.
$ sudo ifdown enp0s3 && sudo ifup enp0s3
Sample output:
Killed old client process Internet Systems Consortium DHCP Client 4.3.3 Copyright 2004-2015 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/enp0s3/08:00:27:12:f8:c1 Sending on LPF/enp0s3/08:00:27:12:f8:c1 Sending on Socket/fallback DHCPRELEASE on enp0s3 to 192.168.1.1 port 67 (xid=0xe3877d4) RTNETLINK answers: Cannot assign requested address Internet Systems Consortium DHCP Client 4.3.3 Copyright 2004-2015 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/enp0s3/08:00:27:12:f8:c1 Sending on LPF/enp0s3/08:00:27:12:f8:c1 Sending on Socket/fallback DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x3080e44d) DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 7 (xid=0x3080e44d) DHCPREQUEST of 192.168.1.105 on enp0s3 to 255.255.255.255 port 67 (xid=0x4de48030) DHCPOFFER of 192.168.1.105 from 192.168.1.1 DHCPACK of 192.168.1.105 from 192.168.1.1 bound to 192.168.1.105 -- renewal in 42937 seconds.
Now, let us run the following command to check whether the new IP address has been assigned or not.
$ ip addr
Sample output:
That's it. Also, You can check after rebooting the system. You will see that the new IP is assigned permanently.
5. Set Multiple IP Addresses to Single Network Interface in Older RPM-based Systems
The following steps are tested on CentOS 7 64 bit server edition. However, the same steps should work on other RPM based systems such as Fedora, and Red hat Linux etc.
Just run the following command to add an additional IP temporarily.
$ sudo ip addr add 192.168.2.150/24 dev enp0s3
You can start using the new IP right away.
To add IP address permanent, just Edit network card configuration file as root user:
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
Add a new IP address as shown below.
IPADDR1="192.168.2.150"
For other IP address, add line "IPADDR2="192.168.3.150". You can add any number of IP addresses one by one.
Save and close the file.
Restart network service using command:
# systemctl restart network
Verify the new IP address using command:
# ip addr
Sample output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:80:63:19 brd ff:ff:ff:ff:ff:ff inet 192.168.1.150/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 192.168.2.150/24 brd 192.168.2.255 scope global enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe80:6319/64 scope link valid_lft forever preferred_lft forever
Similarly, add as many IPs as you want.
As you may noticed, I have been using Class C type addresses throughout guide. I want to assign a different class IP, for example class A. Is it possible? Of course, it is.
Just add the IP address of your choice in the network card config file.
6. Assign Different Class IP Addresses in Debian, Ubuntu Systems
In DEB based systems, edit /etc/network/interfaces file:
$ sudo nano /etc/network/interfaces
Add the IP address:
iface enp0s3 inet static address 10.0.0.105/16
Save and close the file.
Run the following command to take effect the changes.
$ sudo ifdown enp0s3 && sudo ifup enp0s3
Check if the new IP has been added using command:
$ ip addr
Sample output:
Ping the new IP address with command:
$ sudo ping -c 3 10.0.0.105
Sample output:
PING 10.0.0.105 (10.0.0.105) 56(84) bytes of data. 64 bytes from 10.0.0.105: icmp_seq=1 ttl=64 time=0.042 ms 64 bytes from 10.0.0.105: icmp_seq=2 ttl=64 time=0.070 ms 64 bytes from 10.0.0.105: icmp_seq=3 ttl=64 time=0.055 ms --- 10.0.0.105 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.042/0.055/0.070/0.014 ms
Like this way, we can add multiple IPs to single Network card in Ubuntu, Debian and derivatives like Linux Mint, and Elementary OS etc.
7. Assign Different Class IP Addresses in Fedora, RHEL and CentOS Systems
Edit network card configuration file as root user:
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
Add a new IP address as shown below. Please note that you must add correct prefix (netmask) for each class IP range.
Let us add a class A type IP. for example 10.0.0.150.
IPADDR2="10.0.0.150" [...] PREFIX2=16
Make sure the IPADDR number (IPADDR2) and PREFIX number (PREFIX2) are same for each network.
Save and close the file. Restart network service to take effect the changes.
# systemctl restart network
Check the new IP using command:
# ip addr
Sample output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:80:63:19 brd ff:ff:ff:ff:ff:ff inet 192.168.1.150/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 192.168.2.150/24 brd 192.168.255.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 10.0.0.150/16 brd 10.255.255.255 scope global enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe80:6319/64 scope link valid_lft forever preferred_lft forever
Let us ping the IP:
# ping -c 3 10.0.0.150
Sample output:
PING 10.0.0.150 (10.0.0.150) 56(84) bytes of data. 64 bytes from 10.0.0.150: icmp_seq=1 ttl=64 time=0.097 ms 64 bytes from 10.0.0.150: icmp_seq=2 ttl=64 time=0.100 ms 64 bytes from 10.0.0.150: icmp_seq=3 ttl=64 time=0.105 ms --- 10.0.0.150 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1999ms rtt min/avg/max/mdev = 0.097/0.100/0.105/0.012 ms
Why You Should Not Mix Different Class IP Addresses on One NIC?
Ok, we just added IP addresses from different classes in methods 6 and 7. Would that work? Can these systems communicate with other systems that are configured with different classes?
The answer is NO. Systems with different IP classes cannot communicate directly with each other. This is because IP classes are used to divide IP addresses into different networks, and each network has its own unique address range.
When a system tries to communicate with another system on a different network, it needs to use a router to forward the traffic. Routers use the network class of the IP addresses to determine how to route the traffic.
To allow systems with different IP classes to communicate, they must be connected to a router that supports inter-VLAN routing.
VLANs (virtual LANs) are used to divide a physical network into multiple logical networks. Each VLAN can have its own IP address range, and routers can be used to route traffic between VLANs.
Another option is to use a NAT (network address translation) device. NAT devices translate IP addresses from one network to another. This allows systems with different IP classes to communicate directly with each other, even if they are on different physical networks.
If you need to assign multiple IP addresses to a single NIC, it's essential to ensure that these addresses are from the same IP address class and have compatible subnet masks.
Conclusion
To sum it up, you can give a single network card multiple IP addresses in Linux. This is handy when you want different parts of your network to talk to each other, or when you have various services that need separate addresses.
Assigning multiple IP addresses to a single network interface in Linux can be useful for a variety of purposes, such as load balancing, high availability, security, and network segmentation.
Just remember to keep the addresses in the same group (like Class C) so they can communicate, and set up the right routes and gateways for smooth communication.
Related Read:
10 comments
My solution to make multiple addresses.
1. With netctl
[root@localhost ~]# pacman -S netctl
[root@localhost ~]# cp /etc/netctl/examples/ethernet-static /etc/netctl/enp3s0
Description=’A basic static ethernet connection’
Interface=enp3s0
Connection=ethernet
IP=static
Address=(‘192.168.0.23/24’ ‘192.168.3.23/24’)
Routes=(‘192.168.0.0/16 via 192.168.3.1′)
Gateway=’192.168.0.1’
DNS=(‘192.168.0.1’)
## For IPv6 autoconfiguration
#IP6=stateless
## For IPv6 static address configuration
#IP6=static
#Address6=(‘1234:5678:9abc:def::1/64’ ‘1234:3456::123/96’)
#Routes6=(‘abcd::1234′)
#Gateway6=’1234:0:123::abcd’
[root@localhost ~]# netctl start enp3s0
[root@localhost ~]# netctl status enp3s0
2. With nmcli
[root@localhost ~]# nmcli connection add con-name myEthernet ifname net0 autoconnect no type ethernet ip4 192.168.0.64/24 gw4 192.168.0.1
…
root@localhost qq]# nmcli connection modify myEthernet +ipv4.addresses 192.168.3.64/24
root@localhost qq]# nmcli c mod myEthernet ipv4.routes ‘192.168.0.0/16 192.168.3.1’
root@localhost qq]# nmcli connection up myEthernet
root@localhost qq]# nmcli connection show myEthernet
Thanks for sharing.
192.168.0.0/16 are not a A class IP-V4 address, it is a C-class.
So, intstead of guessing wrong, use the command sipcalc(1) or ipcalc(1) to calculat the propper masks and ip addresses.
$ sudo apt-get install sipcalc
$ sipcalc 192.168.1.1/24
-[ipv4 : 192.168.1.1/24] – 0
[CIDR]
Host address – 192.168.1.1
Host address (decimal) – 3232235777
Host address (hex) – C0A80101
Network address – 192.168.1.0
Network mask – 255.255.255.0
Network mask (bits) – 24
Network mask (hex) – FFFFFF00
Broadcast address – 192.168.1.255
Cisco wildcard – 0.0.0.255
Addresses in network – 256
Network range – 192.168.1.0 – 192.168.1.255
Usable range – 192.168.1.1 – 192.168.1.254
–
$ sipcalc 192.168.1.1 255.255.255.0
-[ipv4 : 192.168.1.1 255.255.255.0] – 0
[CIDR]
Host address – 192.168.1.1
Host address (decimal) – 3232235777
Host address (hex) – C0A80101
Network address – 192.168.1.0
Network mask – 255.255.255.0
Network mask (bits) – 24
Network mask (hex) – FFFFFF00
Broadcast address – 192.168.1.255
Cisco wildcard – 0.0.0.255
Addresses in network – 256
Network range – 192.168.1.0 – 192.168.1.255
Usable range – 192.168.1.1 – 192.168.1.254
–
$ echo “Also try different options, like -c”
And use IPv6 instread of IPv4, as IPv6 is supposed to handle many addresses in all machines. IPv4 not so much.
Great stuff. Thank you.
Ah. I wondered about that. The article was saying the IPs were A and the table saying C.
Nmcli is the way to go for Centos, Fedora, RHEL7 and above. The ifconfig command has been depricated. It will not show up interface device aliases and etc…
So make sure NetworkManager service is running, or start it. Then check the full device interface configuration.
Systemctl start NetworkManager
Nmcli con show enp0s3
Furthermore, with nmcli you can also script an IP address change remotely, change hostnames, assign connections SSID and passwords for wireless networks and more.
Nmcli is definitely an efficient solution in the enterprise world
But will it work with adding a public facing internet IP Address like 71.12.34.56.
Some systems say to create an identical nic like enp0s3:0 and enp0s3:1 enp0s3:2.
Maybe this is why I cannot ping outside my network…. doh…
Can I add a second IP inside the same network of the first?
Ex: Add 192.168.1.200/24 and 192.168.1.201/24
Will I be able to ping in both these address?
Yes, it is possible.
Here how i am add a second static IP to the p4p2 interface on my linux machine:
(Feel free to change the interface name based on the NIC of your device. ex: enp1s0 etc )
sudo vi /etc/sysconfig/network-scripts/ifcfg-p4p2\:0
Enter the following 6 lines in the open file: (change the IPADDR accordingly)
TYPE=Ethernet
BOOTPROTO=static
DEVICE=”p4p2:0″
ONBOOT=yes
IPADDR=IPADDR
NETMASK=255.255.255.0
save / quite.
Type ‘sudo ifup p4p2\:0’
Type ‘ip a ‘ to check if the second IP is showing on p4p2 interface
you can add more virtual IP the same way.
The most i have tried was 4 IP assigned to one NIC. ( p4p2:0 to p4p2:3 )