3

I have a Debian based Linux system that I use to troubleshoot a local network which has multiple subnets on the same SOHO switch. If I configure pseudo adapters, I can talk to any machine on any of the subnets:

# ifconfig eth0:1 192.168.1.222
# ping 192.168.1.1 -c1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=0.548 ms
# ifconfig eth0:2 192.168.2.222
# ping 192.168.2.1 -c1
PING 192.168.2.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.2.1: icmp_seq=1 ttl=255 time=0.541 ms

etc.

However, when I unplug the cable from eth0, all the pseudo adapters disappear. I noticed this does not happen with VLANs, however, with those, I have no connectivity:

# vconfig add eth0 2
Added VLAN with VID == 2 to IF -:eth0:-
# ifconfig eth0.2 192.168.2.222
# ping 192.168.2.1 -c1
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
From 192.168.2.222 icmp_seq=1 Destination Host Unreachable

Can I make these VLANs work, or at least make pseudo adapters permanent?

  • 1
    Pseudo adapters are not real adapters, it's just the legacy way for ifconfig to show that multiple IP addresses are bound to the same network interfaces. If you use the more modern ip, you see that directly. You can make IP assignments permanent using various methods, e.g. systemd-networkd or classic /etc/network/interfaces (though I don't know details for multiple IP addresses, hence a comment instead of an answer). – dirkt Feb 15 '17 at 12:06
2

The 'modern' way to add multiple static IP addresses to your physical network interface is

ip address add dev eth0 10.222.222.222/24
ip address add dev eth0 10.222.222.223/24
ip address add dev eth0 172.17.100.1/24
# Repeat as necessary

You can then list all of your network interfaces and addresses using

ip address show

A loop will make adding IP addresses that are in numerically adjacent subnets easier:

# Add 10.200.1.1/24, 10.201.1.1/24, and 10.202.1.1/24 to eth0
for num in 200 201 202; do ip address add dev eth0 10.${num}.1.1/24; done

Note that in this example, the physical interface is called eth0. I'm sure you know what the rest means. My Debian system didn't remove the addresses from the interface when I unplugged the network cable.

To use VLAN with Linux, make sure to load the 8021q module: modprobe 8021q. In most distributions, you can add the module name to /etc/modules (or some variation thereof) to have it loaded at boot time.

The ip command can also be used to add/remove VLANs like so:

# Create VLAN 2 on eth0
ip link add link eth0 name eth0.2 type vlan id 2

# Show information about all available interfaces
ip address show

# Assign 10.222.222.222/24 to eth0.2
ip address add dev eth0.2 10.222.222.222/24

# New VLANs are DOWN by default, so bring VLAN 2 up
ip link set dev eth0.2 up

# Bring the VLAN down prior to removal
ip link set dev eth0.2 down

# Remove the VLAN
ip link del eth0.2

Finally, consider disabling Network Manager if you need to set up slightly complex network configuration (such as logical interfaces, VLANs, or bridging). Network Manager often interferes and undoes your configuration when it detects network-related events.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.