2

How do I create a virtual, always connected network interface with a static IP on Linux? It must work when all my physical interfaces are disconnected.

Looking for general information regarding this, can be for any distribution (Debian, CentOS, Arch Linux etc.)

4
  • 1
    What's wrong with 127.0.0.1? Commented May 4, 2014 at 23:12
  • What do you mean by "conntected"? Commented May 4, 2014 at 23:23
  • Reading b/w the lines I'm assuming you're thinking of a network i/f such as is created by VirtualBox and such, but you want the steps on how to make this yourself? Commented May 4, 2014 at 23:39
  • @Patrick I wanted different/multiple IPs. I forgot I can assign it lo device! Commented May 5, 2014 at 7:17

1 Answer 1

4

You can create as many loopback interfaces as you like and assign IP addresses to them.

In Debian for example you can add:

auto lo:1
iface lo:1 inet static
  address             10.1.1.10
  netmask             255.255.255.255
  dns-nameservers     10.1.1.1

and repeat that with lo:2, lo:3, etc...

If that's not good enough you can create a tun inteface:

auto int1
iface int1 inet manual
  tunctl_user         root
  ip                  ip link set int1 up
  down                ip link set int1 down

You can also create loopback interface manually using ifconfig:

ifconfig lo:2 10.0.0.1 netmask 255.255.255.0

Or using ip:

ip addr add dev lo 10.0.0.1/24 label lo:2

Or using a dummy interface (as suggested by edvinas.me):

ip link add lo3 type dummy
ip addr add dev lo3 10.0.0.1/24
1
  • Worked for me on Ubuntu 20.04. Worth to add, if at some point you want to delete the IP from loopback without restarting the host, you can do so with sudo ip addr del 10.0.0.1/24 brd + dev lo label lo:2 Commented Jan 24, 2022 at 14:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.