Search code examples
ipopenwrtdhcpvlaniproute

Multiple IPs from ISP with DHCP. (OpenWRT or iproute2, macvlan???)


Problem: I want 2 IPs so that I can run two servers on my LAN. Apparently my ISP doesn't allow static IPs and I need to use DHCP to obtain my second IP.

What I have learned so far:

  1. In order to get two distinct IP addresses with DHCP, you need two different MACs (or client IDs?)
  2. You can't have two MACs on a single interface, so you need to put your internet facing interface into promiscuous mode and somehow get that traffic to a virtual interface with its own MAC.
  3. Once the traffic gets to my virtual interface, I can just assign it to WAN firewall zone (OpenWRT thingie, not so important) for ez profit.

But here is the hard part: In order to separate my LAN from WAN there is by default two different VLANs configured in OpenWRT. LAN VLAN is eth0.1 and WAN VLAN is eth 0.2.

The final question is: How do I configure my system? Do I put eth0 in promisc or eth0.2 or both? Or is my premise completely wrong? How do I create the said virtual interface? Below is my ip addr extract.

root@TopLevelRouter:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP qlen 1000
    link/ether [REDACTED] brd ff:ff:ff:ff:ff:ff
    inet6 [REDACTED]/64 scope link
       valid_lft forever preferred_lft forever
9: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether [REDACTED] brd ff:ff:ff:ff:ff:ff
    inet6 [REDACTED]/64 scope link
       valid_lft forever preferred_lft forever
10: wlan1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether [REDACTED] brd ff:ff:ff:ff:ff:ff
    inet6 [REDACTED]/64 scope link
       valid_lft forever preferred_lft forever
16: eth0.1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether [REDACTED] brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global eth0.1
       valid_lft forever preferred_lft forever
    inet6 [REDACTED]/60 scope global noprefixroute
       valid_lft forever preferred_lft forever
    inet6 [REDACTED]/64 scope link
       valid_lft forever preferred_lft forever
17: eth0.2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether [REDACTED] brd ff:ff:ff:ff:ff:ff
    inet [external IP 1]/24 brd [redacted].255 scope global eth0.2
       valid_lft forever preferred_lft forever
    inet6 [REDACTED]/64 scope link
       valid_lft forever preferred_lft forever

Solution

  • I solved it, finally.

    Full solution in my blog

    And a web archive link in case my blog doesn't exist when you read this