Linux : Basic Network Configuration , Set ip,eth0,gateway,netmask Temporarily or Permanent
For latest Redhat Linux OS versions, we can configure
network in few steps.
There are two types of methods are there for network
configuration
- Temporary: In which IP temporarily will be assigned to Ethernet card, and will gone across reboot or network restart.
- Permanent: In which network configuration will be set permanently (in config files), so will be consistent across the reboot or network restart.
We will see both types here, before that we will need few things kinda prerequisite as below:
Sample Set-up Scenario : Linux Static TCP/IP Settings
IP address: 192.168.1.50
Netmask: 255.255.255.0
Hostname: UL_SERVER
Gateway IP: 192.168.1.1
Display All interfaces ( Including Disabled Interfaces )
# ifconfig -a
Dislplay only Active/Enable Ineterface
#ifconfig
Disable and Enable an Interface
# ifconfig eth0 down
# ifconfig eth0 up
Method 1 - Temporary Netwok
Setup
Assign ip-address to an Interface and set netmask and
broadcast for the same
# ifconfig eth0 192.168.1.50
# ifconfig eth0 netmask 255.255.255.0
# ifconfig eth0 broadcast 192.168.1.255
or in a single command
# ifconfig eth0 192.168.1.50 netmask 255.255.255.0
broadcast 192.168.1.255
Set default gateway :
route add default gw 192.168.1.1 eth0
Now we can check and verfiy this configuration like
following :
#ifconfig eth0
eth0 Link
encap:Ethernet HWaddr 00:2D:32:3E:39:3B
inet addr:192.168.1.50
Bcast:192.168.1.255
Mask:255.255.255.0
inet6 addr: fe80::21d:92ff:fede:499b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500
Metric:1
RX packets:977839669 errors:0 dropped:1990 overruns:0
frame:0
TX packets:1116825094 errors:8 dropped:0 overruns:0
carrier:0
collisions:0 txqueuelen:1000
RX bytes:2694625909 (2.5 GiB) TX bytes:4106931617 (3.8 GiB)
Interrupt:185 Base address:0xdc00
# netstat -r //
this command will print Kernel level routing table
Kernel IP routing table
Destination
Gateway Genmask Flags
MSS Window irtt Iface
192.168.1.0 * 255.255.255.0 U
0 0
0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
Note : As its a temporary setup and will be gone across the reboot or network restart
Note : As its a temporary setup and will be gone across the reboot or network restart
Method 2 – Permanent Network Configuration
For static IP configuration you need to edit the
following files. Edit /etc/sysconfig/network as follows, enter:
# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=UL_SERVER
GATEWAY=192.168.1.1
Edit /etc/sysconfig/network-scripts/ifcfg-eth0
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:30:36:56:B1:01
IPADDR=192.168.1.50
NETMASK=255.255.255.0
ONBOOT=yes
Finally, you need to restart the networking service as
below
# /etc/init.d/network restart
Note :- It will be a static permanent network configuration , so will be there across reboot and network restart.
To verify new static ip configuration for eth0
# ifconfig eth0
# route -n
#netstat -rn
That`s it , the very basic network configuration part
done here.
Cheers !!
AJ
Comments
Post a Comment