Linux Format

Establishi­ng a static IP

Stop your server being, to adopt the haughty parlance of the authoritie­s, of no fixed abode.

-

By default, Debian will request an IP address from your router using DHCP. This means though that on next reboot it may well end up with a different IP, which will make SSHing in from elsewhere on the network a challenge and also flummox any port forwarding arrangemen­ts later.

Some broadband routers will allow you to reserve an IP for a machine based on its MAC address, which is one way of solving this problem, but we can also just set up a static IP on our server. We need an address that is of the same shape (by that we mean belonging to the same /24 subnet) as that of your router—the IP address it has already assigned you is a perfectly good choice. You can find this out by running this command # ip a . This will show you all kinds of useful informatio­n about your network interfaces, of which there will probably be at least two: the loopback interface lo and your Ethernet card eth0 . Look for a line such as: inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0

in the eth0 stanza. The 192.168.1.100 part is your machine’s IPv4 (we’re not going to concern ourselves with IPv6 addresses today) address on your home network. Yours will be different (it might not even begin with 192.168), so don’t just copy this blindly. In this case the router’s address will also commence 192.168.1, you can find the last part (you mean octet – Ed) either by already knowing it, by looking on the router’s small print, or by running the command: # netstat -nr

and glancing at the Gateway column (it’s usually 1 or 254). As well as assigning IPs, DHCP also provides routing and DNS informatio­n, so since we’re eschewing DHCP we need to explicitly tell our machine about our network. In Debian this is all done in a file, which the following commands will backup and open: # cp /etc/network/interfaces{,.bak} # nano /etc/network/interfaces

Replace the line iface eth0 inet dhcp

with the following block (leaving intact any preceding lines such as allow-hotplug eth0 ) iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.254 where the gateway address is that of your router. Save this file and exit with Ctrl+x, y, Enter. We also need to tell Debian to use the router for hostname lookups, which involves another file: # nano /etc/resolv.conf

This time delete any lines beginning with nameserver and leave in their place the line: nameserver 192.168.1.254

Again, the IP here is that of your router (which will forward DNS queries to your ISP). You may also prefer to use Google’s DNS servers (8.8.4.4 and 8.8.8.8, multiple nameserver lines are allowed), either way save, exit and go ahead and restart the network with: # systemctl restart networking

Now check you still have connectivi­ty with: # ping -c5 google.com

If you see the following ping: unknown host google.com

then something isn’t right with your nameserver settings, if you see a different error message then your interfaces file needs some tweaking. Try reverting the settings (aren’t backups great for this kind of thing), your router might need a different netmask.

The first thing we want to set up is SSH so that we can log in to our server remotely. Install it with apt-get install openssh-server , which also will start the server. You can try logging by running ssh 192.168.1.100 on a different Linux machine, or using PuTTY in Windows. It’s a good idea to reboot your server at this point to check that the network settings survive a reboot and our SSH server starts. With SSH now working your keyboard, mouse and monitor may be summarily dismissed (which might improve local Feng Shui) and we can continue setting things up from the comfort of another machine (if you want).

“We need an address that is of the same shape as that of your router.”

 ??  ?? The first time you SSH into a machine, you’ll need to confirm the machine’s fingerprin­t. The ip command displays a lot informatio­n for few keystrokes.
The first time you SSH into a machine, you’ll need to confirm the machine’s fingerprin­t. The ip command displays a lot informatio­n for few keystrokes.

Newspapers in English

Newspapers from Australia