Use macvlan to emulate multiple hardware devices on network
1
vote
0
answers
434
views
I am trying to use linux's network name spaces to emulate multiple devices on my local network. I want this to appear as actual network devices, not my laptops IP masquerading on the subnet. Is this possible?
I want to use these namespaces to launch a couple of bash scripts that have internet access, i.e:
sudo ip netns exec netns1 myscript1.sh
sudo ip netns exec netns2 myscript2.sh
I am working on a script to create the virtual network. At the moment I am only attempting to make on namespace:

INTERFACE=enp59s0
IP1=192.168.2.101/24
# create macvlan and associate it to network device in bride mode
ip link add macvlan1 link $INTERFACE type macvlan mode bridge
# create new network namespace
ip netns add netns1
# associate the macvlan to the new namespace
ip link set macvlan1 netns netns1
# Set IP address
ip -n netns1 addr add $IP1 dev macvlan1
# set macvlan to up
ip netns exec netns1 ifconfig macvlan1 up
This lets me ping devices within my subnet, i.e. the following works
sudo ip netns exec netns1 nmap -sn 192.168.2.1-255
However, when I cannot ping the virtual device from default namespace.
In addition, adding the router to route still does not let me connect to the outside world:
sudo ip netns exec netns1 ip route add default via 192.168.2.1
sudo ip netns exec netns1 ping 8.8.8.8
From 192.168.2.1 icmp_seq=1 Destination Net Unreachable
Any ideas?
Is this the right approach?
Would it be better to alias an IP with ifconfig:
ifconfig enp59s0:0 192.168.2.101 up
And then bind the new interface to a namespace somehow?
Asked by Brett Smith
(11 rep)
Jun 15, 2020, 12:37 PM
Last activity: Jun 15, 2020, 01:06 PM
Last activity: Jun 15, 2020, 01:06 PM