Adding Alias IP to a NIC
Jump to navigation
Jump to search
http://www.cyberciti.biz/faq/linux-creating-or-adding-new-network-alias-to-a-network-card-nic/
Using ifconfig command line You can use ifconfig command to configure a network interface and alias. For example: * eth0 NIC IP – 192.168.1.5 * eth0:0 first NIC alias: 192.168.1.6 To setup eth0:0 alias type the following command as the root user: # ifconfig eth0:0 192.168.1.6 up Verify alias is up and running using following command: # ifconfig –a # ping 192.168.1.6 However if you reboot system you will lost your alias. To make it permanent you need to add it network configuration file: If you are using Debian Linux Open the file /etc/network/interfaces: # vi /etc/network/interfaces Append text as follows: auto eth0:1 iface eth0:1 inet static name Ethernet alias LAN card address 192.168.1.7 netmask 255.255.255.0 broadcast 192.168.1.255 network 192.168.1.0 Save the file and restart the network: # /etc/init.d/networking restart If you are using Red Hat / Fedora Linux Copy etc/sysconfig/network-scripts/ifcfg-eth0 file etc/sysconfig/network-scripts/ifcfg-eth0:0 - # cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0 Open file /etc/sysconfig/network-scripts/ifcfg-eth0:0 using vi text editor: # vi /etc/sysconfig/network-scripts/ifcfg-eth0:0 Find entry that read as follows: DEVICE=eth0 Replace with: DEVICE=eth0:0 Find entry that read as follows: IPADDR=xxx.xxx.xxx.xxx Replace it with your actual IP address: IPADDR=192.168.1.7 At the end your file should like as follows: DEVICE=eth0:0 IPADDR=192.168.1.7 NETMASK=255.255.255.0 NETWORK=192.168.1.0 ONBOOT=yes NAME=eth0:0 Open file /etc/sysconfig/network-scripts/ifcfg-eth0 and make sure file does not have a GATEWAY= entry: # vi /etc/sysconfig/network-scripts/ifcfg-eth0 Find the entry that read as follows: GATEWAY=192.168.1.254 Remove or comment it out by prefixing # (hash) : # GATEWAY=192.168.1.254 Save the file. Add the GATEWAY= to your /etc/sysconfig/network: # vi /etc/sysconfig/network Append or modify GATEWAY entry: GATEWAY=192.168.1.254 Save the file. Reboot the system or run the following command: # ifup eth0:0 OR # service network restart See also:
http://www.cyberciti.biz/tips/freebsd-how-to-setup-2-ip-address-on-one-nic.html
It is possible to create network alias or assign 2 ip address to single NIC under FreeBSD. My setup: lnc0 - IP : 192.168.1.1/255.255.255.0 lnc0 alias - IP : 192.168.1.5/255.255.255.255 Note: Netmask must be diffrent otherwise you will get an error ifconfig: ioctl (SIOCAIFADDR): File exists A) From command line use ifconfig command as follows: # ifconfig lnc0 192.168.1.5 netmask 255.255.255.255 alias B) You can setup this alias in /etc/rc.conf file by appending following text, so that next time FreeBSD comes up (after restart/shutdown) it will create alias for you: ifconfig_lnc0_alias0=”192.168.1.5 netmask 255.255.255.255″ C)Restart FreeBSD network service using following script: # /etc/netstart D) Display alias and real ip using ifconfig lnc0 command: # ifconfig lnc0 lnc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 inet6 fe80::20c:29ff:fe01:ddbd%lnc0 prefixlen 64 scopeid 0×1 inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255 inet 192.168.1.5 netmask 0xffff Read ifconfig man page.