March 28, 2011

debian vps ip alias

I needed my Debian VPS to show certain fake IP on ifconfig, so I've applied the following changes to /etc/network/interfaces file
# This configuration file is auto-generated.

# WARNING: Do not edit this file, your changes will be lost.
# Please create/edit /etc/network/interfaces.head and /etc/network/interfaces.tail instead,
# their contents will be inserted at the beginning and at the end
# of this file, respectively.
#
# NOTE: it is NOT guaranteed that the contents of /etc/network/interfaces.tail
# will be at the very end of this file.

# Auto generated lo interface
auto lo
iface lo inet loopback

# Auto generated venet0 interface
auto venet0
iface venet0 inet static
address %DESIRED_FAKE_IP%
netmask 255.255.255.255
broadcast 0.0.0.0
up route add -net %GATEWAY_IP% netmask 255.255.255.255 dev venet0
up route add default gw %GATEWAY_IP%

auto venet0:0
iface venet0:0 inet static
address %REAL_IP%
netmask 255.255.255.0
broadcast 0.0.0.0


If you're using VPS and those changes are getting overwritten on startup, create a new file /etc/network/interfaces.e and put the following script in cron @reboot:
#!/bin/sh
cp /etc/network/interfaces.e /etc/network/interfaces
/etc/init.d/networking restart

No comments: