Wednesday, 23 January 2008

Howto simply configure network card in Debian

Besides presence of eye-candy graphical configurators in Linux, in many situations it is more straightforward to change config files. It is really simple, and below it is shown how to do it.

How to see current network card settings
For brief review of network settings, it is enough to type in command prompt:

# ifconfig
or
sudo ifconfig
And something like this should appear:

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:104 errors:0 dropped:0 overruns:0 frame:0
          TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:9387 (9.1 KiB)  TX bytes:9387 (9.1 KiB)
eth0      Link encap:Ethernet  HWaddr 00:0A:E4:53:AA:2D
          inet addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:21 Base address:0x2c00

It is evident, that there are two interfaces had been configured: loopback named lo, and conventional Ethernet card eth0.


How to configure network connection in Linux
To do so, you need root privileges and _your_favorite_text_editor, as well as knowledge of which IP address you need to enter.

To find out which network interface need to be configured, type:
dmesg | grep -i Eth
and next strings should appear:
8139too Fast Ethernet driver 0.9.28
eth0: RealTek RTL8139 at 0xdf822c00, 00:15:f2:51:ad:da, IRQ 21
eth0: Identified 8139 chip type 'RTL-8101'
It looks like it is eth0 (because ethernet, 0 - zero device, pretty logical). Here and below it is assumed that interface is eth0


Configuring Linux network with static IP
Just edit the file:
# nano /etc/network/interfaces
or
sudo nano /etc/network/interfaces
For your local network static IPs are surely enough. In particular, for static IP networking you need to enter: IP-address, netmask and gateway. Change  /etc/network/interfaces to something like this:
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 192.168.1.5
    netmask 255.255.255.0
    gateway 192.168.1.1
In this example, IP-address 192.168.1.5 is set.


Configuring Linux network with dynamic IP addresses
Continue to edit network config:
# nano /etc/network/interfaces
or
sudo nano /etc/network/interfaces
It is simpler here:
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

Similarly, network interface can be configured via command line:
#dhcpcd eth0
For this, you should install in Debian aptitude install dhcp3-client.


Configuring DNS nameserver in Linux
If you don't configure DNS, you cannot connect to any Internet resource by it's name. But it's very simple to tweak it: just edit or create file /etc/resolv.conf
# nano /etc/resolv.conf
or
sudo nano
/etc/resolv.conf
And type addresses like this:
nameserver   192.168.1.1
nameserver   192.168.2.1
as much as it is need. The word nameserver is required. It is curious, but in fresh Debian installation there is no resolv.conf...


For changes to take place immediately...
... one can reboot the system, or type:
# /etc/init.d/networking restart 
or
sudo /etc/init.d/networking restart 
That's all, changes will be applied for all network interfaces.

6 comments:

Vandy said...

Great help from this How to. Got my ethernet card up and running up and running first time. Thanks

A2Z Uniforms said...

How do you handle my situation. I have a dedicated "cloud" server from 1and1. It has a static IP for the server. I also have paid for 5 additional IP's (total of 6).

None of the tutorials ever tell you how to determine the proper values when you have a server like this and you want to update the /etc/network/interfaces file so that instead of dhcp it has a static IP.

This was working fine. The only problem is that I paid someone to set the server up. I bricked the server and now I am having to set it back up again myself with the little knowledge that I learned from working with him. Each time I update the /etc/network/interface file, and restart the network, it closes my SSH connection and I can never connect to the server again. I then have to re-image the server and start all over. This is getting really old and I feel really stupid!!

Bradley D. Thornton said...

For one thing, if you issue:

[code]
# /etc/init.d/networking restart
[/code]

You won't actually be disconnected if your networking is correctly configured, and the interface you were connected to still exists.

Instead of going into your server via ssh when working with things like sshd or your networking stack, you may instead consider going in via the system console.

A console connection is available on a virtual server whether you are using a provider supplying you with an OpenVZ or a KVM virtualized server.

With OpenVZ you can ssh into the console, which won't become disconnected if you lose your networking stack, and a special console is available via VNC is you have a KVM server.

The howto above in this article touches on several important *concepts* that you really need to understand, not just go through and muck about with.

Although following this guide can give you the abc's, it should also serve to show you those areas you need to grasp an understanding of and know what to expect when working through this guide.

But please, plan to fix your running server via the console instead of re-installing the whole server. There's no reason you should have to follow that MS Windows approach to fixing things.

All the best :)

.

Anonymous said...

I have read through the tutorial a few times, and I intend to understand and follow it.

My situation seems to be a bit bizarre. I chose the Squeeze version of Debian, and installed the desktop environment. During the installation, it asked for two pieces of firmware for the network (which I don't even remember the names).

I used my Windows OS and the command ipconfig to get the required info for my wireless connection.

Then, using the obtained network info, I tried to configure the network both through the GUI environment and the instructions given in this tutorial, but the web browser cannot be loaded yet. The web browser says something about name server issues.

The tutorial implicates that the file /etc/resolv.conf should be created. Is that true?

I seem to be lost. I am not sure whether or not I should blame lack of the firmware. If I knew that the network can be setup even without the firmware, I would only concentrate on doing the manual configuration as described in the tutorial.

Anonymous said...

This Howto solved my problem.
Thanks!

Anonymous said...

Very Handy Bro....
Many Thanks indeed
You saved my time

Cheers
RS