LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-26-2010, 02:28 AM   #1
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 576

Rep: Reputation: 31
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
 
Old 03-26-2010, 02:35 AM   #2
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Bangalore, India
Distribution: Linux Mint 13
Posts: 592

Rep: Reputation: 64
Quote:
Originally Posted by gardenair View Post
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

Last edited by Sayan Acharjee; 03-26-2010 at 02:39 AM.
 
Old 03-26-2010, 02:37 AM   #3
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,628

Rep: Reputation: Disabled
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.
 
Old 03-26-2010, 02:41 AM   #4
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Bangalore, India
Distribution: Linux Mint 13
Posts: 592

Rep: Reputation: 64
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.
 
Old 03-26-2010, 03:05 AM   #5
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 576

Original Poster
Rep: Reputation: 31
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
 
Old 03-26-2010, 03:15 AM   #6
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Bangalore, India
Distribution: Linux Mint 13
Posts: 592

Rep: Reputation: 64
Quote:
Originally Posted by gardenair View Post
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.
 
Old 03-26-2010, 03:17 AM   #7
hardcorelinux
Member
 
Registered: Jan 2005
Location: India
Distribution: RHEL,CentOS,SUSE,Solaris10
Posts: 183

Rep: Reputation: 31
To assign ip adrees from command line simple way is use ifconfig command

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

ifconfig eth0
 
Old 03-26-2010, 03:44 AM   #8
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 576

Original Poster
Rep: Reputation: 31
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
 
Old 03-26-2010, 03:53 AM   #9
hardcorelinux
Member
 
Registered: Jan 2005
Location: India
Distribution: RHEL,CentOS,SUSE,Solaris10
Posts: 183

Rep: Reputation: 31
Try following

ifconfig eth0 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.100 up
 
Old 03-26-2010, 03:53 AM   #10
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Bangalore, India
Distribution: Linux Mint 13
Posts: 592

Rep: Reputation: 64
Quote:
Originally Posted by gardenair View Post
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.

Last edited by Sayan Acharjee; 03-26-2010 at 03:54 AM.
 
Old 03-26-2010, 06:27 AM   #11
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,628

Rep: Reputation: Disabled
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.
 
Old 03-26-2010, 07:37 AM   #12
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 576

Original Poster
Rep: Reputation: 31
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 ?
 
Old 03-26-2010, 08:18 AM   #13
hardcorelinux
Member
 
Registered: Jan 2005
Location: India
Distribution: RHEL,CentOS,SUSE,Solaris10
Posts: 183

Rep: Reputation: 31
Quote:
Originally Posted by gardenair View Post
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 View Post

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

Last edited by hardcorelinux; 03-26-2010 at 08:20 AM. Reason: edit
 
Old 03-26-2010, 08:23 AM   #14
omersattar
LQ Newbie
 
Registered: Feb 2008
Posts: 14

Rep: Reputation: 1
you can also use "setup" command for this purpose.
 
Old 03-26-2010, 08:42 AM   #15
linux_
LQ Newbie
 
Registered: Mar 2010
Location: Pune, India
Distribution: Fedora, CentOS, Ubuntu
Posts: 24

Rep: Reputation: 1
Thumbs up

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.

Last edited by linux_; 03-26-2010 at 08:43 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ip address using command line Ammad Linux - Networking 2 04-24-2007 07:12 PM
How to get an IP Address from command line? Big Dog XII Linux - General 4 01-25-2007 12:54 PM
command line address book program oneferna Linux - Software 3 02-12-2006 03:24 PM
Linux command to assign an ip address seb22 LinuxQuestions.org Member Intro 2 06-12-2005 03:19 AM
Linux command to assign an ip address seb22 Linux - Networking 5 05-24-2005 01:03 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration