Hostname and IP setup

From Smith family
Jump to: navigation, search
Server setup
← Previous Next →
OS installation Firewall

The default setup for allocating IP numbers is dynamically, via DCHP from the router. That's fine for most machines, but server machines need fixed IP numbers. As both Linux machines act as servers, they both need fixed IP numbers.

The first thing to do is to adjust the settings on the router so that some of the IP numbers on the LAN are not in the DHCP pool. While you're there, adjust the settings on the router to open various ports and pass the packets to the server.

Hostname

To give the Linux boxes their hostname, adjust the following files:

  • Change /etc/hostname to
 server
  • Change /etc/hosts to include
127.0.0.1       localhost
127.0.1.1       server.domain.tld       server

Find the hostname with hostname, the domain name with dnsdomainname and the FQDN with hostname -f.

Disable NetworkManager

Change /etc/NetworkManager/NetworkManager.conf so that managed=true and there's no dns=dnsmasq line active:

 [main]
 plugins=ifupdown,keyfile
 #dns=dnsmasq
 
 [ifupdown]
 managed=true

Multiple network cards

One of my machines has two network cards. udev assigns interface names to the cards. The trouble is, it seems to do it randomly. To fix how the interface names are assigned to the NICs, modify the file /etc/udev/rules.d/70-persistent-net.rules to include the naming you want:

# PCI device 0x11ab:0x4320 (skge)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x10b7:0x9200 (3c59x)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
Remember to remove any existing naming rules. Note that you should replace the xx:xx:xx:xx:xx:xx with your cards' MAC addresses.

Static IP numbers

  • To give a network card a static IP number, add a stanza to /etc/network/interfaces
 auto eth0
 iface eth0 inet static
         address 192.168.1.252
         netmask 255.255.255.0
         network 192.168.1.0
         broadcast 192.168.1.255
         gateway 192.168.1.1
         dns-nameservers 192.168.1.252 192.168.1.251
         dns-search domain.tld


  • To give a static IP to a WiFi connection using WPA Supplicant, use this interface stanza:
iface wlan0 inet static
     address 192.168.1.101
     netmask 255.255.255.0
     network 192.168.1.0
     broadcast 192.168.1.255
     gateway 192.168.1.1
     wpa-essid MyWifiID
     wpa-psk my-secret-key

# wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
# iface default inet dhcp
  • Ensure that /etc/resolv.conf is a symbolic link to /run/resolvconf/resolv.conf</run>. If it's still pointing to somewhere with NetworkManager in the name, delete it and recreate it:
 root@desktop:~# rm /etc/resolv.conf 
 root@desktop:~# ln -s /run/resolvconf/resolv.conf /etc/resolv.conf

(make sure the server and desktop get different IP numbers).

Reboot the machines and they should both have their fixed IP numbers.

Changing hostnames

If you change the hostname after setting up the machine, you'll need to change a couple of things that encode the hostname.

First is the OpenSSH server. The server keys will still be labelled with the old hostname. To regenerate the keys, delete them then reconfigure the openssh-server package:

root@server:~# rm /etc/ssh/ssh_host_*
root@server:~# rm dpkg-reconfigure -plow openssh-server

You will then need to remove the key fingerprints from all machines that connect to this server, otherwise the SSH client will complain that the host it's connecting to has changed identity. For each user, remove the line for the given host in ~/.ssh/known-hosts. When you next connect to the host, you'll be asked to confirm the key fingerprint again. (Taken from Vivek Gite's instrutions.)

The other thing is the user table in MySQL. MySQL creates users for the particular hostname. They're easily changed using the MySQL tool:

root@desktop:~# mysql -u 'root' -p 
mysql> update mysql.user set host='newhost.domain.tld' where host='oldhost.domain.tld';
mysql> quit;

External DNS records

I use DomainDiscount24 as a registrar for my domains. Their nameservers provide the canonical source for external DNS lookups for the njae.me.uk domain, among others. The domain settings there are fairly straightforward. I use their standard nameservers (ns1.domaindiscount24.net, ns2.domaindiscount24.net, and ns3.domaindiscount24.net).

The DNS settings are:

IN A 212.69.55.62
MX 10 mail.njae.me.uk
20 mail.microwavesushi.com

Ensure the 'Make wildcard entry' box at the bottom of the page is checked, so that domains such as www.njae.me.uk and mail.njae.me.uk can be resolved.