LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to assign IP address using command line. (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-assign-ip-address-using-command-line-797980/)

gardenair 03-26-2010 01:28 AM

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

Sayan Acharjee 03-26-2010 01:35 AM

Quote:

Originally Posted by gardenair (Post 3912874)
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


You can use this command to configure your network interface from Command line:
Quote:

#system-config-network
And you can use links or elinks command the view webpages in command line:
Quote:

#links www.google.com
#elinks www.google.com
I think you are a little confused about run levels and virtual terminals. In run level 1 you won't find the network service working, but you can start the service with the following command.

Quote:

#service network start

linuxlover.chaitanya 03-26-2010 01:37 AM

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
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:1E:C9:39:7C:D4
ONBOOT=yes
DHCP_HOSTNAME=localhost.localdomain
IPADDR=192.168.1.3
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes

And for your second issue, you can use internet on cli as well. You can use elinks for web browsing. And keep in mind, using root user for no reason is harmful. Create a normal user and su to root when needed.

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.

Sayan Acharjee 03-26-2010 01:41 AM

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.

gardenair 03-26-2010 02:05 AM

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

Sayan Acharjee 03-26-2010 02:15 AM

Quote:

Originally Posted by gardenair (Post 3912898)
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

Use the command below to restart the network service:
Quote:

#service network restart
If PEERDNS=yes then it modifies the /etc/resolv.conf (which is used to specify the dns server) if the DNS directive is set. If using DCHP, then yes is the default.
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.

hardcorelinux 03-26-2010 02:17 AM

To assign ip adrees from command line simple way is use ifconfig command

ifconfig eth0 <yourstaticip> netmask <yournetmask> gateway <yourgateway> up

ifconfig eth0

gardenair 03-26-2010 02:44 AM

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

hardcorelinux 03-26-2010 02:53 AM

Try following

ifconfig eth0 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.100 up

Sayan Acharjee 03-26-2010 02:53 AM

Quote:

Originally Posted by gardenair (Post 3912927)
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

Example:
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.100 up



EDIT: hardcorelinux posted it earlier. :)

linuxlover.chaitanya 03-26-2010 05:27 AM

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.

gardenair 03-26-2010 06:37 AM

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 ?

hardcorelinux 03-26-2010 07:18 AM

Quote:

Originally Posted by gardenair (Post 3913118)
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?

You can open a terminal window in Runlevel 5 and issue same command.Most of the distributions have the options to right click on desktop and open a terminal option or else find out it from your start menu

Quote:

Originally Posted by gardenair (Post 3913118)

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 ?


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..

omersattar 03-26-2010 07:23 AM

you can also use "setup" command for this purpose.

linux_ 03-26-2010 07:42 AM

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:


DEVICE=eth0
BOOTPROTO=static
HWADDR=00:1E:C9:39:7C:D4
ONBOOT=yes
IPADDR=192.168.1.3
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BROADCAST=192.168.1.255
TYPE=Ethernet
USERCTL=no
IPV6INIT=no

You can use vi or nano editor for this purpose.


All times are GMT -5. The time now is 08:43 AM.