Working with IP addresses

From ISPWiki
Jump to: navigation, search

The COREmanager ipdb module includes the ipbind module that can be used for IP address management. This module works with the server's network interfaces, adds and deletes real IP addresses assigned to the network interface. This article describes how the module works on different operating systems.

Adding IP addresses

IP addresses can be added in different ways depending on its family (IPv4, IPv6), and whether the interface is configured to work with IP address from that family (whether there are IP address from the same family that the IP you are going to add). When adding the first IP to the network interface you should also configure the default gateway (those parameters are provided by the ipdb module).

The system will check that the newly created IP address is assigned to the interface and can start listening (to a network port) on that address.

The following notations are used for parameters:

iface
interface name
if_alias
alias for interface (for Linux-based servers, for example eth0:0, eth0:1 , etc.)
ip
IP address
mask
subnetwork mask (prefix length for IPv6) - the ipbind module gets this parameter from ipdb
gateway
subnetwork mask- the ipbind module gets this parameter from ipdb

For adding first IP addresses of a certain family, the following commands are used:

Family Linux FreeBSD
IPv4 ifconfig [iface] [ip] netmask [mask]

route add default gw [gateway]

ifconfig [iface] inet [ip] netmask [mask]

route add default [gateway]

IPv6 ifconfig [iface] add [ip]/[mask]

route add --inet6 default gw [gateway]

ifconfig [iface] inet6 [ip] prefixlen [mask]

route add -inet6 default [gateway]

For adding IP addresses in general, the following commands are used:

Family Linux FreeBSD
IPv4 ifconfig [if_alias] [ip] netmask 255.255.255.255 ifconfig [iface] alias [ip]/32
IPv6 ifconfig [iface] add [ip]/128 ifconfig [iface] inet6 alias [ip]/128


For adding IP address to the physical interface you should also specify information about it in the system's configuration file.

Adding the first IP of the family:

Family Debian-based systems RedHat-based systems FreeBSD
File name /etc/network/interfaces /etc/sysconfig/network-scripts/ifcfg-[iface] /etc/rc.conf
IPv4 auto [iface]

iface [iface] inet static

address [ip]
netmask [mask]
gateway [gateway]
DEVICE=[iface]

IPADDR=[ip]

NETMASK=[mask]

GATEWAY=[gateway]

ONBOOT=yes

ifconfig_[iface]="inet [ip] netmask [mask]"

defaultrouter="[gateway]"

IPv6 auto [iface]

iface [iface] inet6 static

address [ip]
netmask [mask]
gateway [gateway]
DEVICE=[iface]

IPV6ADDR=[ip]/[mask]

IPV6_DEFAULTGW=[gateway]

IPV6INIT=yes

ifconfig_[iface]_ipv6="inet6 [ip] prefixlen [mask]"

ipv6_defaultrouter="[gateway]"

Adding the following IP addresses:

Family Debian-based systems RedHat-based systems FreeBSD
File name /etc/network/interfaces /etc/rc.conf
IPv4 auto [if_alias]

iface [if_alias] inet static

address [ip]
netmask 255.255.255.255
/etc/sysconfig/network-scripts/ifcfg-[if_alias]

DEVICE=[if_alias]

IPADDR=[ip]

NETMASK=255.255.255.255

BOOTPROTO=static

ONBOOT=yes

ifconfig_[iface]_alias[N]="alias [ip] netmask 255.255.255.255"
IPv6 inside the section iface [iface] inet6 static

up /sbin/ifconfig [iface] inet6 add [ip]/[mask]";

/etc/sysconfig/network-scripts/ifcfg-[iface]

IPV6ADDR_SECONDARIES="[ip]/[mask]"

ifconfig_[iface]_alias[N]="inet6 alias [ip] prefixlen 128"

Deleting IP addresses

Deletion of IP addresses depends on IP address family. Interface IP address won't be deleted if it is the primary address of its family of that interface.

The following command is executed for deleting IP address:

Family Linux FreeBSD
IPv4 ifconfig [if_alias] down ifconfig [iface] delete [ip]
IPv6 ifconfig [iface] del [ip]/128 ifconfig [iface] inet6 [ip] delete

Once the command is executed, information about that address will be deleted from server's configuration files.