Let us assume that you already have a NIC which is bound with a static IP address. Then you will have a file called
/etc/sysconfig/network-scripts/ifcfg-eth0
.My ifcfg-eth0
file has the following entries:# File: ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.1
NETMASK=255.255.255.0
BROADCAST=192.168.0.255
NETWORK=192.168.0.0
HWADDR=00:80:48:34:C2:84
Now to bind another IP address to the same NIC, I create a copy of the above file
ifcfg-eth0
and name it as ifcfg-eth0:1
# cd /etc/sysconfig/networking-scripts
# cp ifcfg-eth0 ifcfg-eth0:1
Now just change the values of the DEVICE and IPADDR in the file as follows:
# File: ifcfg-eth0:1And lastly, restart the networking service. If you are using RedHat, then it is as simple as :
DEVICE=eth0:1
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.5
NETMASK=255.255.255.0
BROADCAST=192.168.0.255
NETWORK=192.168.0.0
HWADDR=00:80:48:34:C2:84
# service network restart
Note: If you do not know how to configure a NIC, see my previous posts - How to install a network card in Linux and How to assign an IP address.
3 comments:
This is more of a Debian/Ubuntu method:
in /ect/network/interfaces
you'll see this or something very simular
-------------------------------------------
auto lo eth0
iface lo inet loopback
iface eth0 inet static
address xxx.xxx.xxx.xxx #original
netmask 255.255.255.255
broadcast 0.0.0.0
up ip route replace 169.254.1.1 dev eth0
up ip route add default via 169.254.1.1
--------------------------------------------
Change to something like below
auto lo eth0 eth0:1
iface lo inet loopback
iface eth0 inet static
address xxx.xxx.xxx.xxx #original ip
netmask 255.255.255.255
broadcast 0.0.0.0
up ip route replace 169.254.1.1 dev eth0
up ip route add default via 169.254.1.1
iface eth0:1 inet static
address xxx.xxx.xxx.xxx
netmask 255.255.255.255 #aditional IP
broadcast 0.0.0.0
hi is possible to connect throuh public&privae-lan ip on same NIC
Yes, it is quite possible to use the same NIC card to connect to internet and local area network. In fact come used to call this `Poor Man's Router` back when routers were expensive, isong the built-in NAT/masquerade of the linux kernel to pose as a router with the rest of the lan and the internet comnection both connected to the same switch with the single NIC from the linux box.
Post a Comment