OpenWrt Forum Archive

Topic: Is it possible to create WAN subinterfaces with unique MACs and IPs?

The content of this topic has been archived on 16 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have 5 IP addresses assigned to me by my ISP. I have the linksys wrt54GL with 4MB flash and 16MB RAM. If I throw kamikaze on there, will I be able to somehow be able to use DHCP to grab upto 5 public IPs from my ISP? And then of course I would use iptables to set up NAT forward rules to bind each public IP with a private IP on my home LAN.

For example will I be able to get wan0.0 wan0.1 wan0.2 wan0.3 and wan0.4 to grab say the public IPs 24.1.1.100, 24.1.1.1.101 , 24.1.1.1.102, 24.1.1.103 and 24.1.1.104 via DHCL clien leases from my ISP..and then I would set up NAT forward rules to link 24.1.1.100 to 192.168.1.100 and 24.1.1.101 to 192.168.1.101 on my LAN etc etc? Is this doable?

I just found this thread where it was done with static IP addresses on the wan interface. My problem is that the 5 IPs are dynamically assigned.

http://forum.openwrt.org/viewtopic.php?pid=66096

Is there any way to emulate multiple MAC addresses through the public IP somehow? Or maybe I could add some IPs statically but run a persisten DHCP client script which itself is able to spoof MACs?

Nice howto...

Thanks but this is not really a howto. It is a "how on earth can I do this". Maybe I put this in the wrong section?

Moved to General Discussion (Kamikaze)

There are alias interfaces in linux, named things like eth0:2.  To create them, you can just set an IP on that pseudo-interface and it will be created if it does not exist.

First thing to try is maybe this is supported in UCI by default (though somehow I might doubt it seeing as a multi-ip dynamic setup is probably rather uncommon these days).  To try this, I suppose you may just create additional config interface sections, and set the "ifname" to be "myinterface:0" or "myinterface:1" etc.  But for this to work, it would have to know something about the client ids.

In your case, you want the dhcp client to set them.  It appears that it is possible, but may not be supported in every dhcp client, so you may have to install some more fully-featured dhcp packages if you need this.

See here:
https://dev.archer.edu.au/plone/Members … s-in-linux

To get the alias interface (eth0:0) up using dhcp I then ran the following command

ginga:~# dhcpcd-bin -I 01:00:1e:4f:ab:26:94 eth0:0
err, eth0:0: SO_SOBINDTODEVICE: No such device
ginga:~# dhcpcd.sh: interface eth0:0 has been configured with new IP=137.219.45.220

where the second argument is the HWADDR of eth0 incremented by 0x01 and prefixed with '01:' (as per the dhcpcd manpage - man dhcpcd-bin - search for clientid).  You can see that I got an error, but the interface still comes up with the addy given, so I'm calling that a win smile

In udhcp it seems that the clientid is set by the -c option.  So you might be able to do this:

udhcpc -c 01:00:1e:4f:ab:26:94 -i eth0:0

Where the "94" is the last digit in your mac address incrememted by 1 for each new client ID you need. For subsequent ones, not sure if you keep incrementing both digits.  But best get one alias working first.

You may need to install a more fully-featured client like dhcpcd, if udhcpc does not support adding the alias interfaces.

And once you get this working manually, you will need to make a startup script that runs the appropriate dhcp clients.

Here's a configuration for 8.09rc1 on a wrt54gl.  This isn't for load-balancing--only one wan acts as a gateway at a time (although I believe you can route specific networks with iptables), so you'll have to delete routes and initialize interfaces if you're unplugging often.  This setup uses a seperate wire for each wan and the local lan consists of wireless only.  The four regular ports need crossover cables.  You could try putting all the vlans on a single port, but I'm doubtful this would work.

/etc/init.d/custom-user-startup (append):

ifconfig eth0.2 down && ifconfig eth0.3 down && ifconfig eth0.4 down &&  ifconfig eth0.5 down
ifconfig eth0.2 hw ether 00:xx:xx:xx:xx:AB
ifconfig eth0.3 hw ether 00:xx:xx:xx:xx:AC
ifconfig eth0.4 hw ether 00:xx:xx:xx:xx:AD
ifconfig eth0.5 hw ether 00:xx:xx:xx:xx:AE
ifconfig eth0.2 up && ifconfig eth0.3 up && ifconfig eth0.4 up && ifconfig eth0.5 up

/etc/config/network:

config switch eth0
    option vlan0    "5*"
    option vlan1    "4 5"
    option vlan2    "3 5"
    option vlan3    "2 5"
    option vlan4    "1 5"
    option vlan5    "0 5"

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.0
    option type    bridge
    option proto    static
    option ipaddr    192.168.2.1
    option netmask    255.255.255.0

config interface wan
    option ifname    eth0.1
    option proto    dhcp

config interface wan1
    option ifname    eth0.2
    option proto    dhcp

config interface wan2
    option ifname    eth0.3
    option proto    dhcp
    
config interface wan3
    option ifname    eth0.4
    option proto    dhcp

config interface wan4
    option ifname    eth0.5
    option proto    dhcp

/etc/config/wireless:

config wifi-device wl0
    option type    broadcom
    option channel    1
    option maxassoc    16
    option distance    2000
    option disabled    0

config wifi-iface
    option device    wl0
    option network    lan
    option mode    ap
    option ssid        myssid
    option encryption    psk+psk2
    option hidden    1
    option isolate    0
    option bgscan    0
    option wds        0
    option key        "keykeykeykeykeykey"

/etc/config/dhcp (append):

config dhcp wan1
    option interface    wan1
    option ignore    1

config dhcp wan2
    option interface    wan2
    option ignore    1

config dhcp wan3
    option interface    wan3
    option ignore    1

config dhcp wan4
    option interface    wan4
    option ignore    1

/etc/config/firewall (append):

config zone
    option name    wan1
    option input    REJECT
    option output    ACCEPT
    option forward    REJECT
    option masq    1

config forwarding
    option src        lan
    option dest        wan1

config zone
    option name    wan2
    option input    REJECT
    option output    ACCEPT
    option forward    REJECT
    option masq    1

config forwarding
    option src        lan
    option dest        wan2

config zone
    option name    wan3
    option input    REJECT
    option output    ACCEPT
    option forward    REJECT
    option masq    1

config forwarding
    option src        lan
    option dest        wan3
config zone
    option name    wan4
    option input    REJECT
    option output    ACCEPT
    option forward    REJECT
    option masq    1

config forwarding
    option src        lan
    option dest        wan4

(Last edited by Belfry on 9 Dec 2008, 21:37)

The discussion might have continued from here.