NetworkManager and virtual interfaces

My wireless router is an old Linksys BEFW11S4 (801b). I wouldn’t ask for more in terms of speed, when I’m working from the laptop the bottleneck is the upstream Internet provider (cable), and if I have to transfer massive amounts of data between the laptop and the home computer, I can connect directly into the router with a wire and get 100Mbit.

But there is something my router doesn’t have: static DHCP assignment of addresses. I hate it when I’m on the laptop and I don’t know the IP address of the home computer. I could configure the IP address on the home computer statically, but since I also have to use OpenVPN I’d have to set up dnsmasq so I can get the proper DNS server when connecting to the VPN. Or I could use NetworkManager which would take care of switching the name servers for me.
One solution I found was to have the eth0 interface on the home computer be assigned by the router via DCHP, and have a virtual interface (alias) eth0:0 configured with a static address that I can ssh into.

OK, so I’ve set up the alias in /etc/sysconfig/network-scripts/ifcfg-eth0:0 (I’m not a GUI guy when it comes to configuring the networking, I prefer to go directly on the filesystem and write the file myself – nevertheless, using system-config-network would do the same thing for you).

Except that NetworkManager will not bring the interface alias up. It will bring the main interface up, but not the alias.
After digging a bit, it turns out NetworkManagerDispatcher is at fault, and this is the solution I found:

  • mkdir -p /etc/NetworkManager/dispatcher.d (on a newly installed system it was not created by default)
  • Add this eth-subinterfaces file to /etc/NetworkManager/dispatcher.d:
#!/bin/bash

iface="$1"
shift

action="$1"
shift

if [ "$iface" = "eth0" -a "$action" = "up" ]; then
/sbin/ifup eth0:0
fi
  • Make sure you chmod 0755 /etc/NetworkManager/dispatcher.d/eth-subinterfaces
  • You may or may not have to restart NetworkManagerDispatcher (I think it just worked for me):
    • /sbin/service NetworkManagerDispatcher restart
  • Click on the NetworkManager icon, disable networking and re-enable it.

At this point, ifconfig should show the interface alias.

5 thoughts on “NetworkManager and virtual interfaces

  1. Pingback: NetworkManager et les interfaces virtuelles - even.IT

  2. flo

    Hey,

    Thanks for sharing this tip, it really proves helpful.

    Did the same on an Ubuntu system (8.10), just added:

    * to /etc/network/interfaces:

    auto eth0:0
    iface eth0:0 inet static
    address 192.168.0.2
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255

    * your procedure

    And it worked

    Thanks

    Florent

  3. apexwm

    Thank you very much. Even in Fedora 12, this fix still works GREAT. I tried setting up multiple IP aliases with NetworkManager, however they did not work correctly. With your method, you get the real IP alias devices created.

  4. Cristiano

    Thank you, I’m using Fedora 12 also. Just as a contribution I made de code more generic (supporting more interfaces and aliases):

    #!/bin/bash
    
    iface="$1"
    shift
    
    action="$1"
    shift
    
    if [ "$action" = "up" ]; then
            for ALIAS in /etc/sysconfig/network-scripts/ifcfg-$iface:*; do
                    ALIAS=`echo $ALIAS | cut -d: -f 2`
                    /sbin/ifup $iface:$ALIAS
            done
    fi
    
  5. Pingback: Tip: Configuring network aliases with NetworkManager on Fedora 14 « EdVoncken.NET

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>