An introduction to Debian networking setup
Posted by Steve on Sun 25 Sep 2005 at 13:32
Under Debian networking is pretty comparable to other distributions of GNU/Linux, especially in areas such as DNS setup. However if you're new to the distribution you might not know where things are set. This brief introduction to networking will show you how it works.
Most likely there are only four things you will care about:
- Setting up your hostname
- Setting up DNS.
- Setting up your IP address.
- Setting your default gateway.
Setting up DNSSetting up your hostname upon a Debian installation is very straightforward. You can directly query, or set, the hostname with the hostname command.
As an user you can see your current hostname with:
skx@lappy:~$ /bin/hostname lappyTo set the hostname directly you can become root and run:
/bin/hostname newnameWhen your system boots it will automatically read the hostname from the file /etc/hostname - so if you wish to make a permanent change then you should edit that file, and your change will then be made at bootup time automatically.
Setting up your IP address.When it comes to DNS setup Debian doesn't differ from other distributions. You can add hostname and IP addresses to the file /etc/hosts for static lokups.
To cause your machine to consult with a particular server for name lookups you simply add their addresses to /etc/resolv.conf.
For example a machine which should perform lookups from the DNS server at IP address 192.168.1.1 would have a resolv.conf file looking like this:
search my.flat nameserver 192.168.1.1(Here the search my.flat causes lookups of hostnames to have my.flat appended to them. So lappy would be looked up as lappy.my.flat)
Setting your default gateway.The IP addresses associated with any network cards you might have are read from the file /etc/network/interfaces. This file has documentation you can read with:
man interfacesA sample entry for a machine with a static address would look something like this:
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.1.90 gateway 192.168.1.1 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255Here we've setup the IP addresss (192.168.1.90), the default gateway (192.168.1.1), and the netmask.
For a machine running DHCP the setup would look much simpler:
# The loopback network interface auto lo iface lo inet loopback # The primary network interface - use DHCP to find our address auto eth0 iface eth0 inet dhcp(If you're using a DHCP based setup you must have a DHCP client package installed - usually one of pump or dhcp-client.)
If you make changes to this file you can cause them to take effect by running:
/etc/init.d/networking restart
If you read the previous section then you'll see that the default route for a host with a static IP address can be set in /etc/network/interfaces.
If you wish to view your current default route/gateway then you can run:
lappy:~# netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0Alternatively you can use the route command:
lappy:~# /sbin/route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 * 255.255.255.0 U 0 0 0 eth0 default router 0.0.0.0 UG 0 0 0 eth0(Here the see the hostname router instead of the IP address 192.168.1.1 - to avoid that run "/sbin/route -n").
To change your default route you must first remove the current one:
/sbin/route del default gw 192.168.1.1Once this has done you'll have no gateway and be unable to talk to non-local hosts.
Add the new route with :
/sbin/route add default gw 192.168.1.100
--
Wiktor
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Yes that is certainly something to consider. If you're running any networking services you might have hard-coded references to your old hostname/IP address.
We discussed this briefly when talking about migrating to a new machine.
Steve
--
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
That shouldn't spontaneously occur - unless perhaps you're running a DHCP setup.
If you are you should examine your dhcp-client / pump / whatever settings to stop this from happening ...
Steve
--
[ Parent | Reply to this comment ]
This happens on a fresh install of Sarge, no packages apart from the ones it installs straight away. I change /etc/resolv.conf (because the router I have to use doesn't like Linux for some bizzare reason, despite it using Linux firmware!), and it changes itself back to the wrong DNS. I've tried it with both an automatically assigned IP and a static IP, with no change.
Any help would be appreciated!
[ Parent | Reply to this comment ]
There absolutely *must* be a better way to solve this, so you might be better off waiting for someone more knowledgeable to read your comment than implementing above mentioned workaround. ;-)
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
Thanks for the help so far.
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
If you don't need the package why not simply remove it?
"dpkg --purge packageName", should do the job for you. (The package name might be dhcp-client, dhcp3-client, pump, or something else. You can see which package owns the file by running "dpkg --search /etc/dhclient.conf")
(The later comment about resolvconf seems plausible too ..)
Steve
--
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
After every DHCP lease expiry, dhclient will request a renew and then update your /etc/resolv.conf.
Good news is you can tell it how the update should be done.
Putting the directive
prepend domain-name "my-home.com"
in /etc/dhclient.conf will force dhclient to insert
search my-home.com
into /etc/resolv.conf the next time it updates that file.
Good luck!
Alexandre Ilha
[ Parent | Reply to this comment ]
[ Send Message | View dkg's Scratchpad | View Weblogs ]
The problem is that aquiring a dynamic configuration via DHCP legitimately might suggest changes to /etc/resolv.conf. without the resolvconf package installed the dhcp client program will just overwrite the contents of /etc/resolv.conf in its entirety. Problems immediately arise if there are, say, two clients capable of acquiring (or generating) networking configuration information. does each one wipe out the other one's data? and if you edit the file by hand, that's a third change -- how should the programs cope with this?
with resolvconf installed, you can add whatever permanent settings you need into /etc/resolvconf/resolv.conf.d/base (or .../head or .../tail, if you need the lines to be explicitly at the top or bottom of the generated /etc/resolv.conf), and the file will be managed programmatically. when a new program has resolver information, it tells resolvconf, which then regenerates /etc/resolv.conf appropriately.
[ Parent | Reply to this comment ]
dns-nameservers 1.2.3.4 5.6.7.8
dns-search my.flat
ifup automagically transfers these settings to resolv.conf when the interface is then brought up.
[ Parent | Reply to this comment ]
[ Send Message | View dkg's Scratchpad | View Weblogs ]
If you need the settings to be always available, yer better off putting it in /etc/resolvconf/base, but if you only want that setting to be available when a particular interface is up, you should certainly put that setting in /etc/network/interfaces.
[ Parent | Reply to this comment ]
if the internet interface is using dhcp-client and you better use dhcp3-client and dhcp3-server, then you are prepaired for a ddns setup.
you need to do this,
apt-get remove --purge dhcp-client
apt-get install dhcp3-client
in /etc/dhcp3/dhclient.conf
# /etc/dhcp3/dhclient.conf
supersede domain-name "setyourdomain.here.com";
prepend domain-name-servers 127.0.0.1;
thats all.
no need for resolvconf
i used it and removed it.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View dkg's Scratchpad | View Weblogs ]
[ Parent | Reply to this comment ]
Mike
[ Parent | Reply to this comment ]
The proper way to change from dhcp to static, is to shutdown networking with "/etc/inti.d/networking stop" (or "ifdown eth0"), make your changes in /etc/network/interfaces from dhcp to static, and then bring back up the network with "/etc/init.d/networking start" (or "ifup eth0"). And it sure doesn't hurt to do a "ps aux | grep dhclient" before you make the change to make sure dhclient is really dead.
Hope this helps someone, as I know a good number of my students have pulled out some hair with this one.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
-duncan
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View dkg's Scratchpad | View Weblogs ]
For a two-interface machine without ifrename, which network interface gets "eth0" and which one gets "eth1" is determined by which module is loaded first (if they rely on different kernel modules) or by some other arbitrary method (if they rely on the same kernel module). This can get especially dicey during a kernel upgrade or a hotplug upgrade because you don't know for sure which /etc/network/interfaces stanza is going to apply to which NIC.
ifrename lets you specify (in /etc/iftab) what the actual interface should be named based on some set of matching criteria (such as the MAC address, which is built into the adapter itself). Here's an example /etc/iftab for a laptop to make sure that the wired and wireless NICs are always bound to the same name:
#/etc/iftab for a laptop with two NICs wired mac AB:CD:EF:01:02:03 wireless mac 45:67:89:0A:0B:0CWhen writing your own /etc/iftab, you'll need to see what the actual mac addresses are for your current arrangement. You can do this easily with: /sbin/ifconfig -a | grep HWaddr
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Damn, I was saving that for a seperate article!
Oh well, definitely a good tip. Thanks for adding it here.
Steve
--
[ Parent | Reply to this comment ]
I'm particularly interested in the case when one of the boxes has *only* the netinst stuff on it (ie how to bring it to a full Debian via files on another 'full' Debian box)
Ta, Michael
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
You could use scp if you have openssh installed on both machines - or for more general purpose sharing you could install an FTP server, Samba server, or NFS server.
Using scp to transfer files is probably sufficient ..
You have lots of options and without more details about the kind of sharing you wish to do it is hard to know what to say!
Steve
--
[ Parent | Reply to this comment ]
I wish to get files such as sudo & ssh deb packages onto the 2nd computer - currently resorting to booting both into XP to do this! ie how to get files from one to the other in the first instance (so can install apps such as those you list). Once done that I'll finally set up the server as an apt repository for the latter
Ta, Michael
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Telnet won't help you much.
At the point you installed presumably you had network access - so if you still have that you should be able to install the openssh package. If your network isn't working properly then you could look elsewhere for help getting it working ..
I guess you could save the openssh*.deb files onto floppy from the XP side, but that might be a bit paintful!
Steve
--
[ Parent | Reply to this comment ]
I think I should be able to use NFS between the two I have here... now trying that
ta,M
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
There isn't anything specific in place for doing that.
However you can cause scripts / commands to be executed as interfaces are brought up - either by adding them to /etc/network/interfaces, or by placing them in /etc/network/if-up.d.
For an example of the former approach you can see this snippet:
auto eth0
iface eth0 inet static
address 192.168.1.42
network 192.168.1.0
netmask 255.255.255.128
broadcast 192.168.1.0
up route add -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2
up route add default gw 192.168.1.200
down route del default gw 192.168.1.200
down route del -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2
I hope that helps!
Steve
--
[ Parent | Reply to this comment ]
1) How do you specify a fully qualified domain name? Is that merely a by-product of /etc/hosts?
2) Just a point of information, multiple search'es can be specified to search multiple domains, but unlike nameservers they must all be declared on the same line. I've seen this problem crop up many times, often any error (multiple search lines) makes NO searching work-- big problem.
Thanks for the great article, I'll make sure to add it to my welcome to debian kit.
[ Parent | Reply to this comment ]
And for those who don't know, if you are running a DCHP server and want your linux clients to have a search stanza for the domain, simply have the DHCP server hand out the domain name. The effect on a Debian Sarge client is to add the domain's appropriate search stanza to the /etc/resolve.conf file before the nameserver entries.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
You don't know how long I've been annoyed by Apache telling me "apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName".
Now that message is gone forever :-)
[ Parent | Reply to this comment ]
The author of this article would surely be welcome to help with the maintenance of the Debian Reference. ;)
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
:)
Steve
--
[ Parent | Reply to this comment ]
auto eth0 eth1
mapping eth*
script /usr/local/sbin/map-scheme
iface eth inet static
...
where /usr/local/sbin/map-scheme contains:
mac=$(/sbin/ifconfig "$1" | \
sed -n '/^.*HWaddr \([:[:xdigit:]]*\).*/{s//\1/;y/abcdef/ABCDEF/;p;q;}')
test "$mac" = XX:XX:XX:XX:XX:XX
echo eth
where XX:XX:XX:XX:XX:XX is the MAC address.
[ Parent | Reply to this comment ]
Although it is debian article i would like to ask my question because after all it is based on debian. I have installed ubuntu 5.4 on my P-3 650MHZ PC on second hard disk's 4th partition which is 40 GB today.After installtion is completed when i log in to windows 2000, I found that all my partitions on second drive have gone. Can I retrieve all my data? Is there any solution to my problem? why ubuntu arase all partitions on my second drive?
Please help me.
Thank you
[ Parent | Reply to this comment ]
You'd be better off asking on an Ubuntu mailing list. Ubuntu is not Debian, and you've not provided enough details for anybody to help..
[ Parent | Reply to this comment ]
My problem regarding disappearing disks has been solved by logged into rescue mode. But still my Grub boot loader is not installed correctly.
My system settings are:
Machine name: HP-BRIO
Operating System: Windows 2000 Professional (5.0, Build 2195) Service Pack 4
Language: English (Regional Setting: English)
System Manufacturer: Hewlett-Packard
System Model: HP Brio
BIOS: Default System BIOS
Processor: Intel Pentium III, ~650MHz
Memory: 192MB RAM
Page File: 79MB used, 379MB available
Windows Dir: C:\WINNT
I have Two Hard disks. On Fist one I installed win-2000 and on second 40GB, which was partitioned as four parts D(6GB), E(6GB), F(6GB), and G (22GB). I have installed RedHat-9 (now it is Ubuntu 5.4) on G drive. My Bios can read only unto 33GB. That is why Red Hat leave 8GB space as not-usable and installed the Base system on usable(I mean BIOS readable) space.
If you are thinking why I am saying all this? When I installed Ubuntu It took all space!
Is it possible to access all the space?
I reinstalled Ubuntu in hdd3 and installed grub boot loader on root partition (Linux root hdd3) and with the command #
dd if=/dev/hdd3 of=/bootsect.lnx bs=512 count=1
created bootsect.lnx . Then copy bootsect.lnx file to C:\ for start up screen to change OS. When I reboot and try to login to Linux Grub say gnome error. Should I choose MBR option to install grub? Hope you got my problem (I follow this procedure in red hat. It works well).
[ Parent | Reply to this comment ]
So please place question in propper place.
1) A tread discussing bootloaders.
2) A Umbuntu place (becouse you get better help, if there are differences between the two distributions)
BUT, you should NOT do "dd ..." to install bootloader. If it works in another distributions doesn't mean it works in same way in Debian (and other way around).
Do "dpkg-reconfigure -plow grub" OR manualy edit /boot/grub/meny.list and reinstall boot loader (see grub documentation at /usr/share/doc/grub or man pages).
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
#cat /etc/resolv.confand was greeted with "DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN". So I didn't know where to add nameserver information. But this page made me aware of the
resolvconf package and its files. Boy, what a lifesaver because I was getting "ping: host not found" errors. Thanks to everyone here!
[ Parent | Reply to this comment ]
(When trying to perfom "/sbin/..." )
[ Parent | Reply to this comment ]
We're trying to add a Debian computer to a small office network. We can ping the other computers but cannot ping outside the LAN. The Windows computers can ping outside the LAN. Any suggestions? Thanks
[ Parent | Reply to this comment ]
Compare deb:"traceroute debian.org" win:"tracert debian.org".
The first hop should/will be the gateway - i.e. the connection to the internet.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View Weblogs ]
...Rob
The American Dream isn't an SUV and a house in the suburbs; it's Don't Tread On Me.
[ Parent | Reply to this comment ]