On Ubuntu, I need to make it seem like there are multiple, independent machines on a real network. This needs to be done without creating any additional VMs. At first, I thought of IP address aliasing, which kinda worked. For example, my machine's adapter is named enp0s3 and it has an IP address of I want other machines to see an additional machine on the network at I used the below command to achieve that:

sudo ip a add dev enp0s3

This works great, but the mac addresses for and .15 are the same, which is not acceptable.

I tried simply changing the mac address, but that changes it for both .14 and .15.

What's the solution? I know it is possible because if I add an additional VirtualBox network adapter it has its own IP and mac address. I can't use that solution because I need to emulate so many machines (50+).

The closest answer I found was this Stack Exchange post.

Thanks in advance for your help!

1 Answer 1


You can create multiple network namespaces, each with their own ip address, and connect them together any way you want.

For example, let's say we want to simulate three nodes sharing a private network. First we create a bridge device that will represent the network:

ip link add name br-net0 type bridge
ip addr add dev br-net0
ip link set br-net0 up

Which gets us:

# ip addr show br-net0
3: br-net0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 2a:06:b9:b4:e9:61 brd ff:ff:ff:ff:ff:ff
    inet scope global br-net0
       valid_lft forever preferred_lft forever

Next, we'll create network namespaces to represent out fake machines:

# ip netns add node0
# ip netns add node1
# ip netns add node2

Next, we create three veth pairs that we'll use to connect our namespaces to the bridge:

ip link add name node0-ext type veth peer name node0-int netns node0
ip link add name node1-ext type veth peer name node1-int netns node1
ip link add name node2-ext type veth peer name node2-int netns node2

Each of these commands creates a veth pair, and puts one end of the pair in the named network namespace. We need to connect the "outside" end of each pair to our bridge:

ip link set master br-net0 dev node0-ext
ip link set master br-net0 dev node1-ext
ip link set master br-net0 dev node2-ext

Finally, we need to (a) assign addresses to our virtual nodes:

ip netns exec node0 ip addr add dev node0-int
ip netns exec node1 ip addr add dev node1-int
ip netns exec node2 ip addr add dev node2-int

The ip netns exec command lets us run commands inside a network namespace (you can also do this using nsenter).

And (b) bring up all the interfaces:

for node in 0 1 2; do
  ip link set node${node}-ext up
  ip netns exec node${node} ip link set node${node}-int up

Now, we have three virtual nodes, each with a unique ip address and MAC address:

# ping -c 1
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=0.054 ms

--- ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.054/0.054/0.054/0.000 ms
# arp -an
? ( at 52:54:00:90:73:ca [ether] on eth0
? ( at ba:0b:4b:ed:e4:bb [ether] on br-net0
? ( at da:38:38:32:29:17 [ether] on br-net0
? ( at 56:ad:09:af:46:1f [ether] on br-net0

Mininet is a great tool for automating this sort of setup.

  • Thanks! What if I wanted the nodes to be on my actual network (not a private one)? Aug 11, 2022 at 15:01
  • Put them on a bridge that is shared by your physical NIC (and assign addresses from the appropriate network range).
    – larsks
    Aug 11, 2022 at 15:12
  • 1
    What would be the command to create that bridge? Would it be using bridge-utils? Aug 11, 2022 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .