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 |
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 |
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? |
yeah me too, i understand the first command but not the second :s
Thanks |
Quote:
/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 |
Does this make the nic card always use this address or will go back to DHCP when rebooted?
G |
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 |
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 |
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 |
Quote:
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. |