LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Assigning ip to network device (https://www.linuxquestions.org/questions/linux-networking-3/assigning-ip-to-network-device-132873/)

Jestrik 01-08-2004 06:12 PM

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

homey 01-08-2004 06:17 PM

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

timmy_laf 01-08-2004 06:24 PM

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?

Jestrik 01-08-2004 06:30 PM

yeah me too, i understand the first command but not the second :s

Thanks

homey 01-08-2004 06:46 PM

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

gabaus 01-08-2004 07:46 PM

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

G

timmy_laf 01-08-2004 08:29 PM

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

Jestrik 01-09-2004 04:44 AM

That's helped loads :D

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

gabaus 01-09-2004 11:17 AM

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

homey 01-09-2004 03:11 PM

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=


All times are GMT -5. The time now is 02:56 PM.