FreeBSD Setup 2 IP address on One NIC ( IP alias )
It is possible to create network alias or assign 2 ip address to a single NIC under FreeBSD operating system.
Sample 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
Set ip alias using ifconfig command line utility
Login as the root user.
Now, use ifconfig command as follows to set alias:
# ifconfig lnc0 192.168.1.5 netmask 255.255.255.255 alias
Persistent IP Alias Configuration
Edit file /etc/rc.conf to setup persistent ip aliasing option by appending following configuration, 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"
Finally, < href="http://www.cyberciti.biz/tips/freebsd-how-to-start-restart-stop-network-service.html">Restart FreeBSD network service using network restart script:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart
Display alias and real ip using ifconfig lnc0 command:
# ifconfig lnc0
Sample output:
lnc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 inet6 fe80::20c:29ff:fe01:ddbd%lnc0 prefixlen 64 scopeid 0x1 inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255 inet 192.168.1.5 netmask 0xffff
Sample /etc/rc.conf file with IP aliasing
Here is my /etc/rc.conf file with em0 and em1 interface with 5 aliases:
hostname="sun.nixcraft.in" # default vsnl router interface defaultrouter="202.54.1.200" # Force 10Mbps for both public and private LAN interace ifconfig_em0="inet 10.20.110.2 netmask 255.255.255.192 media 10baseT/UTP mediaopt full-duplex" ifconfig_em1="inet 202.52.1.2 netmask 255.255.255.248 media 10baseT/UTP mediaopt full-duplex" ifconfig_em0_alias0="inet 10.20.1.226 netmask 255.255.255.0" ifconfig_em0_alias1="inet 10.20.1.227 netmask 255.255.255.0" ifconfig_em0_alias2="inet 10.20.1.228 netmask 255.255.255.0" ifconfig_em0_alias3="inet 10.20.1.229 netmask 255.255.255.0" ifconfig_em0_alias4="inet 10.20.1.230 netmask 255.255.255.0" # static routing configuration static_routes="lan0" route_lan0="-net 10.0.0.0/8 10.20.110.1"
Further readings:
- Read ifconfig man page.
Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
You may also be interested in other helpful articles:
- FreeBSD > How to change IP address or setup new ip address to existing interface
- FreeBSD > How to setup FreeBSD as DNS client?
- How to export display from Linux to FreeBSD
- Linux How to setup multi homing network
- FreeBSD: How To List Device Drivers ( modules ) Loaded In Memory
Discussion on This Article:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: /etc/rc.conf, freebsd ifconfig alias, freebsd ip alias, freebsd ip aliasing, freebsd netmask, freebsd network alias, freebsd network ip alias, freebsd networking, ifconfig command, ifconfig ip alias, ip alias, ip networking, nic, set ip alias



i want to configure in one networkcard 2 ip adress
Hi,1st 0f all u r explaining 2 ip alias nd this proccess is very lenthy .i create 2 multiple NIC alaises like this;:-go t 1st network-scripts nd type dis command “cp ifcfg-eth0 ifcfg-eth0:1″.
nd put in ur ip nd netmask as u like.very easy process.u can tell me where m i wrong nd ur daily blog reader.
Regards
Raju Dutta Tiwari
Raju,
This is tutorial about FreeBSD and not about Red Hat Linux. Your instructions only applies to Linux and not to FreeBSD.