Several virtual networks with only one physical interface

Hi,

Anyone could help me, please?

I've got a OpenWrt system with only one physical interface.
I would need to generate up to 8 virtual interfaces to appear as different machines on the network.
If possible, I would like to get dhcp addresses from the router for the 8 interfaces.
I've tried a lot of different configurations of /etc/config/network, but I didn't manage to get anything that works.
For example, with:
/etc/config/network

config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config interface 'lan'
	option ifname 'eth0'
	option ipv6 '0'
	option igmp_snooping '0'
	option multicast_querier '0'
	option proto 'static'
	option ipaddr '192.168.1.91'
	option netmask '255.255.255.0'
	option gateway '192.168.1.1'
	option dns '8.8.8.8'
	option macaddr 'D4:91:AF:60:00:01'

config interface 'lan2'
	option ipv6 '0'
	option ifname 'eth0.2'
	option ipaddr '192.168.1.92'
	option netmask '255.255.255.0'
	option gateway '192.168.1.1'
	option dns '8.8.8.8'
	option proto 'static'
	option macaddr 'D4:91:AF:60:00:02'
 
config interface 'lan3'
	option ipv6 '0'
	option ifname 'eth0.3'
	option ipaddr '192.168.1.93'
	option netmask '255.255.255.0'
	option gateway '192.168.1.1'
	option dns '8.8.8.8'
	option proto 'static'
	option macaddr 'D4:91:AF:60:00:03'
		
config globals 'globals'
	option ula_prefix 'fd56:3b56:d85c::/48'

we get in ifconfig:

eth0      Link encap:Ethernet  HWaddr D4:91:AF:60:00:01
          inet addr:192.168.1.91  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2649 errors:0 dropped:0 overruns:0 frame:0
          TX packets:186 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1742277 (1.6 MiB)  TX bytes:45114 (44.0 KiB)
          Interrupt:36

eth0.2    Link encap:Ethernet  HWaddr D4:91:AF:60:00:02
          inet addr:192.168.1.92  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:3951 (3.8 KiB)

eth0.3    Link encap:Ethernet  HWaddr D4:91:AF:60:00:03
          inet addr:192.168.1.93  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:96 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:7311 (7.1 KiB)

But from other computer doing ping, only 192.168.1.91 interface is available on the network.

The interfaces eth0.2 and eth0.3 are interfaces for VLAN 2 and VLAN 3. Is your switch VLAN capable or the other device you are pinging from?

If I understood your question correctly, you want your single ethernet port to acquire 8 different IP addresses via DHCP, all on the same network. No segregation (VLANs) involved, right?

VLANs cannot be in the same network. All of the networks you have defined are using the same subnet... they must be different.

What is the actual goal you are trying to achieve here? Are you trying have the router itself use 8 different addresses? If so, to what end? What is the purpose of having the router use more than 1 address? Or are you trying to setup 8 different DHCP servers? Or maybe 8 DHCP reservations for your downstream devices?

Yes, that's it. The idea is to have several instances of one service running in the same machine, connected to different IPs, so each one appears as a different device and accessed throught the same ports independently.

Maybe the only way to do it is using Namespaces or docker.

You can easily have multiple IP addresses when configured statically. They all need to be in the same subnet, though.

As noted, any interface can be configured with multiple addresses within the same subnet.

Alternatively, you could setup additional networks if you need different subnets. If you were to do this, the router would respond to requests with a destination of one of these additional addresses provided that input is permitted from the source zone/host.

All of that said, all the addresses would have equal functionality insofar as any services running on the router would be accessible on all of the addresses that the router holds (you could theoretically change this behavior with the firewall, but that would need to be proven out for whatever you goal is).

When all is said and done, I don't see any real value in assigning additional IPs to the router for your generally stated goal. It is trivially easy, though, to set the dns entries such that multiple hostnames would map to the same host (i.e. the router in this case), so if that's the goal, I'd go that approach rather than adding multiple addresses/interfaces.

I've managed to do it by creating namespaces with ip netns and using macvlan driver. Thank you all. The service runs inside that namespaces with ip netns exec.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.