Linux – Creating Virtual Network

In Linux you can easily create a virtual network. You can do this by using the “ifconfig” command. Remember to have the root privilege before you can try this.

Note: This tutorial is for those who have access to the physical machine directly. By changing the network configuration, might end up terminating your connected session.

Steps

1. Issue the “ifconfig” command in your command prompt. This is to check the existing network configuration. For testing purpose, we will doing this on the loopback (127.0.0.1) interface.

Existing output:

eth0      Link encap:Ethernet  HWaddr 00:c0:4f:88:31:7a
inet addr:192.168.1.4  Bcast:192.168.1.255  Mask:255.255.255.0
inet6 addr: fe80::2c0:4fff:fe88:317a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:61153 errors:0 dropped:0 overruns:0 frame:0
TX packets:190113 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21723068 (20.7 MB)  TX bytes:13325627 (12.7 MB)
Interrupt:11 Base address:0xc000

lo          Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:16436  Metric:1
RX packets:4569 errors:0 dropped:0 overruns:0 frame:0
TX packets:4569 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:200919 (196.2 KB)  TX bytes:200919 (196.2 KB)

2. Now to create the 1st virtual network. Issue the “ifconfig lo:1 127.0.0.3” command.

3. Then for the 2nd virtual network. Issue the “ifconfig lo:2 127.0.0.4” command.

4. Verify your newly created virtual network by running “ifconfig” command. You should see the output as below:

lo:1      Link encap:Local Loopback
inet addr:127.0.0.3  Mask:255.0.0.0
UP LOOPBACK RUNNING  MTU:16436  Metric:1

lo:2      Link encap:Local Loopback
inet addr:127.0.0.4  Mask:255.0.0.0
UP LOOPBACK RUNNING  MTU:16436  Metric:1

Advertisements

One thought on “Linux – Creating Virtual Network

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s