How to assign IP address using command line.
Hi,
I am using internet in my home PC using Red Hat 9. To assign static IP to my linux machine I use "System Settings....> Network" and then double click on "eth0" to assign the static IP. Well these all settings by using GUI interface.Kindly guide me that if I use only command line interface "runlevel 1" then in that case which file should i edit and assign my static IP, Subnet Mask, Default Gateway DNS settings. 2- 2nd thing is,is there any way that I may open web broswer in command line? or the administrator should only use internet on Run Level 5 ? thanks in advance for the help. gardenair |
Quote:
You can use this command to configure your network interface from Command line: Quote:
Quote:
Quote:
|
You can edit corresponding file in /etc/sysconfig/network-scripts/ifcfg-ethX and put all the information there. Take a look at my file and use it as reference.
Code:
# Broadcom Corporation NetLink BCM5787 Gigabit Ethernet PCI Express Also you are using a VERY OLD distribution and it is not supported any more. You will not receive any updates on RH9 and you should consider upgrading to newer one. |
And as linuxlover.chaitanya said you can edit that file as well to configure the network. don't forget to restart the service after editing the file.
|
thanks a lot for the help. Well i get the file but sorry i does't know which service how how to restart it.
Please mention the name and method to restart the service after configuring the IP address. 2- what is USERCTL=no PEERDNS=no just explain a bit.thanks |
Quote:
Quote:
If PEERDNS=no then it doesn't modify /etc/resolv.conf. If USERCTL=yes means Non-root users are allowed to control this device. If USERCTL=no then non-root users are not allowed to control this device. |
To assign ip adrees from command line simple way is use ifconfig command
ifconfig eth0 <yourstaticip> netmask <yournetmask> gateway <yourgateway> up ifconfig eth0 |
Thanks "Sayan acharjee" and "Hardcorelinux" for the replies.Well i am happy that we have another way (as hardcore mentioned) to configure the ip address.
ifconfig eth0 <yourstaticip> netmask <yournetmask> gateway <yourgateway> up There is a little confusion that there is a space between then example ifconfig eth0 192.168.1.1 255.255.255.0 192.168.1.100 up |
Try following
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.100 up |
Quote:
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.100 up EDIT: hardcorelinux posted it earlier. :) |
But I guess this change is not permanent. You will need to re assign the address once the system or the service restarts.
To make changes persistent over reboots you will need to edit the file. |
Well i am little confuse now...I switch to (Runlevel 5) and in the terminal i edit the network interface eth0 file.It does't say to restart the service. but as "sayan_acharjee" wrote
Use the command below to restart the network service: #service network restart This command is use when we r using Runlevel 1 or 3 but what about If i use GUI, open the terminal (Just for testing and experiment purpose) and change the IP address then which command should I give to restart my network services? 2- If I give the command ifconfig eth0 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.100 up it say "bash: ifconfig:command not found" well where i am doing wrong ? |
Quote:
Quote:
issue following command which ifconfig most probabaly it will be under /usr/sbin/ifconfig , so run command using full path of binary ie: /usr/sbin/ifconfig eth0 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.100 up Are you trying to do this as root user or a normal user ? If it is as a normal try this logged as root user.. |
you can also use "setup" command for this purpose.
|
Hello everybody,
I think editing the file /etc/sysconfig/network-scripts/ifcfg-ethx is a recommended way to assign static IP. I have tried this on CentOS and it worked for me. I would suggest few modifications in the settings given by linuxlover.chaitanya Code:
|
All times are GMT -5. The time now is 11:50 PM. |