LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices



Reply
 
Search this Thread
Old 01-08-2004, 07:12 PM   #1
Jestrik
Member
 
Registered: Dec 2003
Location: Hampshire, UK
Distribution: gentoo, Debian Sarge, Slack 9.1
Posts: 206

Rep: Reputation: 30
Assigning ip to network device


How do you give a NIC an ip, i've looked everywhere but all i get is how to do it via the gui. I want to know how to do it in the bash shell.

Cheers
 
Old 01-08-2004, 07:17 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Try this...
/sbin/ifconfig -a eth0 192.168.0.2 netmask 255.255.255.0
/sbin/route add default gw 192.168.0.1

You can check them with /sbin/ifconfig and /sbin/route respectively.


Edit: sorry that should have been /sbin/ifconfig

Last edited by homey; 01-08-2004 at 07:39 PM.
 
Old 01-08-2004, 07:24 PM   #3
timmy_laf
Member
 
Registered: Jan 2004
Location: Western Australia
Distribution: Mandrake Linux 9.2
Posts: 78

Rep: Reputation: 15
with the ips that r in the command...

can u substitute ur own or do u have to uses those ones??? please explain step by step what the command does?
 
Old 01-08-2004, 07:30 PM   #4
Jestrik
Member
 
Registered: Dec 2003
Location: Hampshire, UK
Distribution: gentoo, Debian Sarge, Slack 9.1
Posts: 206

Original Poster
Rep: Reputation: 30
yeah me too, i understand the first command but not the second :s

Thanks
 
Old 01-08-2004, 07:46 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Quote:
/sbin/ifconfig -a eth0 192.168.0.2 netmask 255.255.255.0
/sbin/route add default gw 192.168.0.1

/sbin is the location of the executable programs called ifconfig and route.
So, to run them you have to include the location unless your logged in as root.

You can check the various options with man ifconfig

The example I used can be changed to match your needs... Basically, I said to add the ip address of 192.168.0.2 to the nic known as eth0 . I also said that the subnet mask is 255.255.255.0 and the next command said that my router is using the ip address of 192.168.0.1
 
Old 01-08-2004, 08:46 PM   #6
gabaus
LQ Newbie
 
Registered: Oct 2003
Posts: 3

Rep: Reputation: 0
Does this make the nic card always use this address or will go back to DHCP when rebooted?

G
 
Old 01-08-2004, 09:29 PM   #7
timmy_laf
Member
 
Registered: Jan 2004
Location: Western Australia
Distribution: Mandrake Linux 9.2
Posts: 78

Rep: Reputation: 15
I have found out that this will always reset on reboot like the previous message suggests, the only way to make it permanent is to set it via your distro's contaol panel.

Hope this helps,
Tim
 
Old 01-09-2004, 05:44 AM   #8
Jestrik
Member
 
Registered: Dec 2003
Location: Hampshire, UK
Distribution: gentoo, Debian Sarge, Slack 9.1
Posts: 206

Original Poster
Rep: Reputation: 30
That's helped loads

To set it in the distros control panel do you need to be in a GUI? Would I be able to edit the config file that the distros control panel saves to? Or would it be different with each different distro?

Cheers
 
Old 01-09-2004, 12:17 PM   #9
gabaus
LQ Newbie
 
Registered: Oct 2003
Posts: 3

Rep: Reputation: 0
I believe the file is called

/etc/sysconfig/network-scripts/ifcfg-eth0 (if your nic is eth0)

I'm not sure of the syntax. Maybe someone else can step in here.


G
 
Old 01-09-2004, 04:11 PM   #10
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Quote:
I want to know how to do it in the bash shell.
Ok, so if you want to use the GUI tools in Redhat, Type the command:redhat-config-network which will open up a nice GUI.

If you want to add the ip address information manually, it would look something like this.... You can change the numbers and hostname around to suit yourself.

Edit the file /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
USERCTL=no
ONBOOT=yes
BOOTPROTO=none
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
NETMASK=255.255.255.0
IPADDR=192.168.1.2

and the file /etc/sysconfig/network.

NETWORKING=yes
HOSTNAME=comp1.mydomain.com
FORWARD_IPV4=yes
GATEWAYDEV=
GATEWAY=192.168.1.1


Edit the file /etc/sysconfig/network-scripts/ifcfg-eth0 to use DHCP.
DEVICE=eth0
USERCTL=no
ONBOOT=yes
BOOTPROTO=dhcp
BROADCAST=
NETWORK=
NETMASK=
IPADDR=

Edit the file /etc/sysconfig/network to use DHCP.
NETWORKING=yes
HOSTNAME=
FORWARD_IPV4=yes
GATEWAYDEV=
GATEWAY=
 
  


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
3c905C network card in docking station. Cannot activate network device eth0. pathelms Linux - Networking 4 04-12-2006 03:55 PM
Network card not working? Cannot activate network device eth0 lifeonitsown Linux - Networking 1 11-17-2005 07:30 AM
assigning multiple device aliases to single drive cerealdaemon Linux - General 5 07-26-2005 12:55 AM
Assigning IP numbers on home network moonmoth Linux - Newbie 3 11-18-2004 12:28 PM
no network device?!?! sjefke37 Linux - Newbie 8 03-28-2004 01:58 PM


All times are GMT -5. The time now is 05:38 PM.

Main Menu
Advertisement
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