Syed Jahanzaib Personal Blog to Share Knowledge !

November 14, 2009

*nix- Howto Change IP Address from CLI

Filed under: Linux Related — Syed Jahanzaib / Pinochio~:) @ 6:07 AM

Today, i just installed a new OS on a computer. i installed fedora 11, n i have to change my ip adress, Originally when i installed the os, i set it to DHCP, but now i want to change it to a static ip. so if you are in the same situation as i am, maybe you can learn from this on how you can change your ip address ..

these are the steps i took to make it happen

1. login as root

2. get your current IP address with this command:

ifconfig

The OUTPUT will look someting like this:

[root@host ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:D0:BC:08:09:BC
inet addr:70.238.17.69 Bcast:255.255.255.255 Mask:255.255.255.248
inet6 addr: fe80::2d0:b7ff:fe08:9bb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7174 errors:0 dropped:0 overruns:0 frame:0
TX packets:2305 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5339910 (5.0 MiB) TX bytes:170109 (166.1 KiB)

 

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:34 errors:0 dropped:0 overruns:0 frame:0
TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4275 (4.1 KiB) TX bytes:4275 (4.1 KiB)

OR you can also get the ip from the network configuration file wit this command:
COMMAND to show configuration:

cat /etc/sysconfig/network-scripts/ifcfg-eth0

THe OUTPUT will look like this (i have it set to DHCP)

DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:D0:B7:08:09:BB
ONBOOT=yes

OUTPUT for static IP (example)

#
# File: ifcfg-eth0
#
DEVICE=eth0
IPADDR=192.168.1.100
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
#
# The following settings are optional
#
BROADCAST=192.168.1.255
NETWORK=192.168.1.0

3. Ok, on step 3 we are going to change from DHCP to static ip. so send this command to edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file: (im using nano, but you can use vi if you want)

nano /etc/sysconfig/network-scripts/ifcfg-eth0

Change from this:

# Intel Corporation 82557/8/9 [Ethernet Pro 100]
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:D0:B7:08:09:BB
ONBOOT=yes

TO this:

# File: ifcfg-eth0
#
DEVICE=eth0
IPADDR=192.168.1.100
NETMASK=255.255.255.248
BOOTPROTO=static
ONBOOT=yes

4. now save your changes and reboot your server.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: