Thursday, July 30, 2009

How do I add an IP address to a linux server?

Its for a website in the server, just need to add an IP and its been awhile since I touched a linux server. Do I need to map it to one of the NICs?

How do I add an IP address to a linux server?
This is a quick guide on adding IPs to a system manually. I would only suggest it if you are not using a control panel, such as cpanel, that has a feature to adds ips. If your main ethernet device is eth1 instead of eth0 simply substitute eth1 for eth0. Other then that should be pretty simple to follow, this should work on any standard redhat/centos based system.














Login as root then do the following to add a new ip address to any linux redhat based system. If you have cpanel there is a nice little ip management script that just lets you do it via WHM. For those without cpanel do the following:





cd /etc/sysconfig/network-scripts





Then as a usual precaution I would make a backup of the file


cp ifcfg-eth0 ifcfg-eth0.bak


(you wont need to do anything with the backup)





Then copy the config for your new IP


cp ifcfg-eth0 ifcfg-eth0:1





Then we need to edit the new config


pico -w ifcfg-eth0:1





The lines you need to change:





DEVICE="eth0"


to


DEVICE="eth0:1"





Then change the


IPADDR="xxx.xxx.xxx.xxx"


to be your NEW ip address (it will have your primary ip listed)





Once this is done, press CTRL + X


then press Y and %26lt;enter%26gt;





This will have saved the config for you and the interface is ready to be brought up. This is done with


/sbin/ifup eth0:1





Having done this if you type


/sbin/ifconfig





You should see something like


------code------


eth0 Link encap:Ethernet HWaddr 00:00:00:00:00:00


inet addr:xxx.xxx.xxx.xxx Bcast:xxx.xxx.xxx.xxx Mask:255.255.254.0


UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1


RX packets:55818546 errors:0 dropped:0 overruns:0 frame:0


TX packets:46167836 errors:0 dropped:0 overruns:0 carrier:0


collisions:0 txqueuelen:100


RX bytes:3299680715 (3146.8 Mb) TX bytes:1890963825 (1803.3 Mb)


Interrupt:11 Base address:0xd000





eth0:1 Link encap:Ethernet HWaddr 00:00:00:00:00:00


inet addr:NEW.IP.ADDRESS Bcast:xxx.xxx.xxx.xxx Mask:255.255.254.0


UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1


Interrupt:11 Base address:0xd000





lo Link encap:Local Loopback


inet addr:127.0.0.1 Mask:255.0.0.0


UP LOOPBACK RUNNING MTU:16436 Metric:1


RX packets:241244 errors:0 dropped:0 overruns:0 frame:0


TX packets:241244 errors:0 dropped:0 overruns:0 carrier:0


collisions:0 txqueuelen:0


RX bytes:66571100 (63.4 Mb) TX bytes:66571100 (63.4 Mb)


------/code------





If you then try to ping your new ip it should all work fine


This should also restart eth0:1 on a reboot as its a direct copy of the eth0 config. So checking for the ONBOOT="yes" in ifcfg-eth0:1 will ensure it DOES come back up on a reboot
Reply:Just so long as your ISP has given you an IP try these,





http://www.portlock.com/products/storage...





http://www.cae.wisc.edu/site/public/?tit...





Have fun but be safe.
Reply:Try "man ifconfig".


No comments:

Post a Comment