| cyberiantiger ( @ 2008-11-25 10:16:00 |
Assign yourself multiple static IP addresses
Want to know how to get multiple public static IP addresses via DHCP?
You need:
1) An internet connection which is configured via DHCP.
2) A linux machine connected directly (not via a NAT box).
What's that? DHCP assigned addresses aren't static unless you pay for them you say?
If you configure your linux box to use dhcpcd (on ubuntu just uninstall all the other crap dhcp clients), then invoke it with a -s "$IP", it will request that IP address, and you will get it if it is currently available, it is best to run DHCP normally once, and then from that point on tell your dhcp client to request the first IP address you were assigned.
In Ubuntu this can be done by editing /etc/default/dhcpcd, and adding the following lines in the right place:
Where eth1 is the interface you're want to use the address 55.55.55.55 on.
Ok, so the next question, you only have one interface connected to the internet, how do you run two different DHCP clients on it?
You don't, you make another interface using the following ip voodoo:
This creates a new interface eth2 which uses the existing hard interface eth1.
The new interface can be removed with this voodoo:
On ubuntu this can be achieved in a permanent fashion by editing /etc/network/interfaces and adding the following voodoo:
Notice the extra code to assign a mac address to the interface, if we do not do this then it receives a random mac address, which will cause our static IP address hack to fail.
Edit: It turns out you need to leave eth1 unconfigured and add multiple interfaces using macvlan otherwise the dhcpcd on eth2 confuses the dhcpcd on eth1, I've fixed the full configuration but not the rest of this post.
/etc/network/interfaces
/etc/default/dhcpcd
Want to know how to get multiple public static IP addresses via DHCP?
You need:
1) An internet connection which is configured via DHCP.
2) A linux machine connected directly (not via a NAT box).
What's that? DHCP assigned addresses aren't static unless you pay for them you say?
If you configure your linux box to use dhcpcd (on ubuntu just uninstall all the other crap dhcp clients), then invoke it with a -s "$IP", it will request that IP address, and you will get it if it is currently available, it is best to run DHCP normally once, and then from that point on tell your dhcp client to request the first IP address you were assigned.
In Ubuntu this can be done by editing /etc/default/dhcpcd, and adding the following lines in the right place:
eth1)
OPTIONS='-s 55.55.55.55'
;;Where eth1 is the interface you're want to use the address 55.55.55.55 on.
Ok, so the next question, you only have one interface connected to the internet, how do you run two different DHCP clients on it?
You don't, you make another interface using the following ip voodoo:
# ip link add link eth1 eth2 type macvlanThis creates a new interface eth2 which uses the existing hard interface eth1.
The new interface can be removed with this voodoo:
# ip link del eth2On ubuntu this can be achieved in a permanent fashion by editing /etc/network/interfaces and adding the following voodoo:
iface eth2 inet dhcp
pre-up ip link add link eth1 eth2 type macvlan
pre-up ifconfig eth2 hw ether 55:55:55:55:55:55
post-down ip link del eth2
auto eth2Notice the extra code to assign a mac address to the interface, if we do not do this then it receives a random mac address, which will cause our static IP address hack to fail.
Edit: It turns out you need to leave eth1 unconfigured and add multiple interfaces using macvlan otherwise the dhcpcd on eth2 confuses the dhcpcd on eth1, I've fixed the full configuration but not the rest of this post.
/etc/network/interfaces
# Loopback interface.
auto lo
iface lo inet loopback
# Internet facing interface.
iface eth1 inet manual
auto eth1
# Macvlan device (fake internet facing interface).
iface eth2 inet dhcp
pre-up ip link add link eth1 eth2 type macvlan
pre-up ifconfig eth2 hw ether 55:55:55:55:55:55
post-down ip link del eth2
auto eth2
# Another macvlan device (fake internet facing interface #2).
iface eth3 inet dhcp
pre-up ip link add link eth1 eth3 type macvlan
pre-up ifconfig eth3 hw ether 66:66:66:66:66:66
post-down ip link del eth3
# Local network device.
iface eth0 inet static
address 10.0.0.1
netmask 255.255.255.0
pre-up iptables-restore < /etc/iptables.rules
auto eth0
/etc/default/dhcpcd
case ${INTERFACE} in
eth0)
#SET_DNS='yes'
#SET_HOSTNAME='yes'
#SET_NTP='yes'
#SET_YP='yes'
# Add other options here, see man 8 dhcpcd-bin for details.
OPTIONS=''
;;
# Real internet interface
# Note, we do not use the ISP assigned DNS servers, hostname, etc (Do you trust your ISP?)
eth2)
OPTIONS='-s 55.55.55.55'
;;
# Virtual internet interface
# Note, we do not use the ISP assigned DNS servers, hostname, etc (Do you trust your ISP?)
eth3)
OPTIONS='-s 66.66.66.66'
;;
*)
;;
esac