1

I'm testing a network program on Ubuntu. Is there any way to create a virtual network interface in Ubuntu. Something like lo is good, but unfortunately there is bunch of packets on lo with 127.0.0.1 as source and destination IP addrress.

0

You can add another loopback interface using following command:

ip link add name mylo type dummy
ifconfig mylo up

Use mylo as loopback interface.

0

USE CASE: To create a persistent VIP address in a server to function as a 'loopback' address

Change to /etc/systemd/network/ directory

user@server:~$ cd /etc/systemd/network/

Create two files, 'vip.netdev' and 'vip.network'

user@server:/etc/systemd/network$ touch vip.netdev vip.network

Show the newly created files

user@server:/etc/systemd/network$ ls
vip.netdev  vip.network

Edit the two files with your favorite editor to reflect the detail below

user@server:/etc/systemd/network$ more vip.netdev
[NetDev]
Name=vip
Kind=dummy

... and ...

user@server:/etc/systemd/network$ more vip.network
[Match]
Name=vip

[Network]
Address=172.16.1.23 (or whatever address you so choose)
Mask=255.255.255.255
Broadcast=172.16.1.255 (match the Address x.x.x.255)

Enable the newly created VIP interface w/out rebooting the server

user@server:/etc/systemd/network$ systemctl restart systemd-networkd

Show the newly create VIP interface

user@server:/etc/systemd/network$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.1.16  netmask 255.255.255.0  broadcast 172.16.1.255
        inet6 fe80::20c:29ff:fe9b:703f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:9b:70:3f  txqueuelen 1000  (Ethernet)
        RX packets 244  bytes 32605 (32.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 653  bytes 51807 (51.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 411  bytes 66247 (66.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 411  bytes 66247 (66.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vip: flags=195<UP,BROADCAST,RUNNING,NOARP>  mtu 1500
        inet 172.16.1.23  netmask 255.255.0.0  broadcast 172.16.255.255
        inet6 fe80::d0a7:56ff:fe83:95ff  prefixlen 64  scopeid 0x20<link>
        ether d2:a7:56:83:95:ff  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7  bytes 490 (490.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

... or ...

user@server:/etc/systemd/network$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:9b:70:3f brd ff:ff:ff:ff:ff:ff
    inet 172.16.1.16/24 brd 172.16.1.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe9b:703f/64 scope link
       valid_lft forever preferred_lft forever
3: vip: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
    link/ether d2:a7:56:83:95:ff brd ff:ff:ff:ff:ff:ff
    inet 172.16.1.23/16 brd 172.16.255.255 scope global vip
       valid_lft forever preferred_lft forever
    inet6 fe80::d0a7:56ff:fe83:95ff/64 scope link
       valid_lft forever preferred_lft forever

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.