Sungju's Slow Life

Personal journal


Creating virtual networks with NetworkManager

In Linux, you can create a virtual network – aka. vlan. To create it you need to create a file under /etc/sysconfig/network-scripts/ directory.

For example, if you want to create a virtual network for eth0, you need to create a file something like below. Here I created with a tag 0.

$ cat /etc/sysconfig/network-scripts/ifcfg-eth0:0

DEVICE="eth0:0"
BOOTPROTO=static
IPADDR=172.16.0.1
NETMASK=255.255.255.0
NM_CONTROLLED="no"

If you does not use NetworkManager service, it is very easy. Just need to restart network service.

$ service network restart

http://pagead2.googlesyndication.com/pagead/show_ads.js

But, if you try to use NetworkManager service, it fails to show this virtual network device properly.

To make it work properly, you need to create a dispatcher file like below.

$ cat /etc/NetworkManager/dispatcher.d/00-virtip
  
#!/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`
    if [ "$ALIAS" = '*' ]; then
      break
    fi
    /sbin/ifup $iface:$ALIAS
  done
fi

This file should have a execution permission. So, set the permission like below and also restart network and NetworkManager service.

$ chmod a+x /etc/NetworkManager/dispatcher.d/00-virtip
$ service network restart
$ service NetworkManager restart

Now it will show you virtual network as well.



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: