marți, 5 noiembrie 2013

Linux networking setup

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 your hostname
Setting 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 
To set the hostname directly you can become root and run:
/bin/hostname newname
When 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 DNS
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 would have a resolv.conf file looking like this:
search my.flat
(Here the search my.flat causes lookups of hostnames to have my.flat appended to them. So lappy would be looked up as
Setting up your IP address.
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 interfaces
A 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
Here we've setup the IP addresss (, the default gateway (, 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
Setting your default gateway.
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   U         0 0          0 eth0         UG        0 0          0 eth0
Alternatively you can use the route command:
lappy:~# /sbin/route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface     *        U     0      0        0 eth0
default         router         UG    0      0        0 eth0
(Here the see the hostname router instead of the IP address - to avoid that run "/sbin/route -n").
To change your default route you must first remove the current one:
/sbin/route del default gw
Once 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

Niciun comentariu:

Trimiteți un comentariu