Multiple IP addresses on Debian

Quick post. If you have multiple IP addresses (i.e. a range) assigned to you server, and you want to listen on all of them (i.e. multiple SSL sites), then rather than using the ancient eth0:1 syntax, you can hack /etc/network/interfaces to use iproute2 properly.

Assuming the IP 10.2.3.4, with the extra range of 10.5.4.110-10.5.4.118 (yes these extra ranges often ignore class-boundries):

auto eth0
iface eth0 inet static
    address 10.2.3.4
    netmask 255.255.255.0
    network 10.2.3.0
    broadcast 10.2.3.255
    gateway 10.2.3.1
    # Extra IPs:
    post-up for last in `seq 110 118`; do ip addr add 10.5.4.$last/32 dev $IFACE; done || true
    pre-down for ip in `ip addr show dev $IFACE | sed -n ‘s@.* inet \([0-9.]*/32\) .*@\1@ p’`; do ip addr del $ip dev $IFACE; done || true

Yes, it’s ugly as shit, but I can’t think of a neater way to do it.

Update: Better solution

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Pingback

[...] Multiple IP addresses on Debian [...]

Ubuntu (probably Debian too) r

Ubuntu (probably Debian too) runs scripts in the sub-directories

Oops... sorry... "if-pre-up.d"

Oops... sorry...
"if-pre-up.d", if-up.d", "if-down.d" and "if-post-down.d" of /etc/network. I create a script called /etc/network/if-up.d/routes for additional IP addresses and special routes, based on this template:

if [ "$IFACE" = "eth0" ]; then
# Do "ip addr add" and "ip route add" here
fi

I have what I think is a prett

I have what I think is a prettier solution at http://andyk.za.net/Blog/2007/12/07_-_Multiple_IP_Addresses_in_Ubuntu

addresses script

This might be a better solution: http://wertarbyte.de/debian/addresses

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.