Linux setting a server to static ip and server name


I have written an app which will run on a server. I have little experience with network configuration and such things.

Now I have set-up the server and everything works how I want however I want 2 things

  1. set the ip of my server to a static ip
  2. ideally be able to acces the server with a url like mytestserver.test or something like that

I do have experience with command line linux and windows but never needed to do anything with networks as I usually work with embedded systems

e\ my distribution is debian on the raspberry pi

Best Answer

Static IP

This is how to set up a static IP in Ubuntu if I recall correctly, it should also work in Debian and likely other Debian based distros:

You need to edit the network interfaces file located at /etc/network/interfaces, e.g.

nano /etc/network/interfaces

You should see a line like

iface eth0 inet dhcp

Comment this out with # and instead add:

iface eth0 inet static

EDIT: Explanation of network parameters

Address - Just the IP address of the server, this can be whatever you want as long as it's in the right subnet and not already used on your network

Netmask - This affects just what addresses you can use, for a home network this is almost certainly

Network - the address of the entire network, this is the first address in your subnet and will be the same first three sections as address and end with 0 on a typical home configuration

Broadcast - this one is the last address in the subnet, usually has the same first three sections as the address and ends with a 255 on a typical home network

Gateway - the address of the route, on a typical home network this is usually the second on the subnet (e.g. or

Alter with your own network parameters if they differ. Now, for DNS, edit /etc/resolv.conf and add a nameserver, e.g.:


You might be able to change the nameservers in the interfaces as well, but I can't remember for sure.

After you've done this, you'll need to restart the networking service:

/etc/init.d/networking restart

Setting a Host on Your Local Machine to Access a Dev Web Address

This is the easiest way to access your dev server at an address, but it'll only work for the machines you specifically set it for. I hope that's okay. You just need to edit the /etc/hosts file. Like so: mytestserver.test

Replace the IP address with the one for your server if different.

If you're on Windows the hosts file is at C:\windows\system32\drivers\etc. I think the syntax is the same.

Related Question