Maximum PC

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 requests an IP address from your router using DHCP. This means, though, that on the 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 enable 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 shows you all kinds of useful informatio­n about your network interfaces, of which there are probably 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 address (we’re not going to concern ourselves with IPv6 addresses today) 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 in 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 back up 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, then 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 eserver settings. If you see a different error message, then en your

interfaces file needs some tweaking. Try revertingi­ng the settings—aren’t backups great for this kind of thing? g? 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 starts rts the server. You can try logging in by running ssh 192.168.1.1008.1.100 on a different Linux machine, or using PuTTY in Windows.ndows. It’s a good idea to reboot your server at this point, to o check that the network settings survive a reboot, and ourur SSH server starts. With SSH now working, your keyboard,yboard, 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).

With SSH now working, your keyboard, mouse, and monitor may be summarily dismissed (which might improve local feng shui).

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

Newspapers in English

Newspapers from United States