Howto: Set static ip-address from shell

Diverse kjekke linux tips og triks :)

Howto: Set static ip-address from shell

Postby raisor » 05 Jan 2010, 15:25

Here is a quick guide to show you how to change your network config from be'ing a DHCP client to a host with a static ip address.

First, edit the following file:
Code: Select all
sudo vi /etc/network/interfaces

The configuration in this file should look something like this:
Code: Select all
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

You need to change it to something like this:
Code: Select all
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address 10.0.0.221
        netmask 255.255.255.0
        network 10.0.0.0
        broadcast 10.0.0.255
        gateway 10.0.0.138

Okay you are almost done, you have now configured your computer for static ip.
But to connect to internet you need to specify one or more DNS servers.
You can do that by editing the following file:
Code: Select all
sudo vi /etc/resolv.conf

Add the DNS server(s) provided by your ISP.
If you have a little more advanced network at home or work, and you have a local DNS server then you should add this server instead..
The servers that I use for this example is the ones specified by my mothers ISP (Telenor).
Code: Select all
nameserver 130.67.15.198
nameserver 193.213.112.4
raisor
Power User
 
Posts: 297
Joined: 23 May 2007, 12:54

Return to Linux howto's

Who is online

Users browsing this forum: No registered users and 1 guest

cron