If you are new to Unixmen, you may want to subscribe : ![]()
![]()
![]()
![]()
|
28 June 2009
Posted in
Linux tutorials -
Linux tutorials
Static IP addresses are manually assigned to a computer by an administrator. The exact procedure varies according to platform. This contrasts with dynamic IP addresses, which are assigned either by the computer interface or host software itself, as in Zeroconf, or assigned by a server using Dynamic Host Configuration Protocol (DHCP).
Even though IP addresses assigned using DHCP may stay the same for long periods of time, they can generally change. In some cases, a network administrator may implement dynamically assigned static IP addresses. In this case, a DHCP server is used, but it is specifically configured to always assign the same IP address to a particular computer. This allows static IP addresses to be configured centrally, without having to specifically configure each computer on the network in a manual procedure.
In the absence of both an administrator (to assign a static IP address) and a DHCP server, the operating system may assign itself an IP address using state-less autoconfiguration methods, such as Zeroconf.
1. login as root
2. get your current IP address with this command:
ifconfig
The OUTPUT will look someting like this:
Unixmen-net:~ # ifconfig
eth0 Link encap:Ethernet HWaddr 00:0D:9D:57:44:90
inet addr:10.33.17.143 Bcast:10.33.17.255 Mask:255.255.255.0
inet6 addr: fe80::20d:9dff:fe57:4490/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:255590 errors:0 dropped:0 overruns:0 frame:0
TX packets:98902 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:124649019 (118.8 Mb) TX bytes:14457923 (13.7 Mb)
Interrupt:21
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:18 errors:0 dropped:0 overruns:0 frame:0
TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1060 (1.0 Kb) TX bytes:1060 (1.0 Kb)
OR you can also get the ip from the network configuration file with 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
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:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
(you can other editor if you want like gedit pico nano..emacs)
Change from this:
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:D0:B7:08:09:BB
ONBOOT=yes
TO this:
# File: ifcfg-eth0
#
DEVICE=eth0
IPADDR=10.33.17.143
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
4. now save your changes and reboot your server.


This works fine for a local network but does not take into account routing, etc. So if you change this and don't know how to manipulate the routing tables you will only be able to see 10.33.17.0/24.
Unless I am missing something - I think you would get more mileage out of this.
DEVICE=eth0
0
0
0
0
0
BOOTPROTO=static
HWADDR=00
ONBOOT=yes
IPADDR=10.1.1.2
NETMASK=255.255.255.0
GATEWAY=10.1.1.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes