Network configuration – Static IP on Linux

Most probably, one of the first setting you want to do will be to assign a static IP of our server among your local network and start configuring your router and domain name.

Networks explanation

Indeed, if you start to install services (Like a website, a torrent client, a jukebox, etc…), you have to make sure all the ports are open and redirected to the correct machine and your domain name is well configured.

But to do so, you need first to make sure the IP of your server will not change. Hence you need to set a static IP into the /etc/network/interfaces file.

Type:

<pre class="lang:default decode:true">sudo nano /etc/network/interfaces

and mine is the following:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.0.110
netmask 255.255.255.0
gateway 192.168.0.1

The part that interest us is iface eth0 inet static and then set the address IP you want (Usually 192.168.0.xxx or 192.168.1.xxx depending on your router configuration) while the netmask is always the same.

After modification, just save (CTRL+X then Y) and restart your network

sudo /etc/init.d/networking restart

 

Don’t know your IP?

If you don’t know your local IP address on your server or the gateway, you could check the current automatic (DHCP) configuration.

Just type:

sudo ifconfig

and you should have something similar to that:

eth0      Link encap:Ethernet  HWaddr 50:e5:49:36:be:6e  
          inet addr:192.168.0.110  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::52e5:49ff:fe36:be6e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20171368 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42393767 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:9008655783 (8.3 GiB)  TX bytes:56675394936 (52.7 GiB)
          Interrupt:41 Base address:0xe000

My local IP address is then 192.168.0.110.

And for the gateway, it is most of the case 192.168.0.1 if your IP is 192.168.0.xxx and will be 192.168.1.0 is your IP is 192.168.1.xxx

Gravatar

Loves to discover web-based apps to install on his own server@home and write articles about it

0 Comments:

Add a comment