Debian / Ubuntu Server Network Setup

HOSTNAME

vi /etc/hostname # short name is fine
hostname HOSTNAME # idem
vi /etc/hosts # long name FOLLOWED BY short name

DEAL WITH NETPLAN (since artful)

cp -pi /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.dist
vi /etc/netplan/01-netcfg.yaml

    eth0:
      dhcp4: no
      dhcp6: no
      addresses:
       - x.x.x.x/xx
      gateway4: x.x.x.x

dpkg -l | grep ifupdown #should be empty
dpkg -l | grep netscript #should be empty
#systemctl restart systemd-networkd.service
netplan generate
netplan apply
ping -c1 opendns.com

Note. this is yaml, indentation is important

Note. if you need to setup static routes e.g.,

  routes:
   - to: x.x.x.x/xx
     via: x.x.x.x

https://www.howtoforge.com/tutorial/ubuntu-minimal-server-install/2/

OR DISABLE NETPLAN

Switch to old school /etc/network/interfaces

apt update
apt install ifupdown

and disable netplan with a kernel argument,

netcfg/do_not_use_netplan=true

Make sure there is no shit lying around

cd /etc/network/interfaces.d/
ls -lhF
#cat 50-cloud-init.cfg

Proceed with old-school Debian setup

cp -pi /etc/network/interfaces /etc/network/interfaces.dist
vi /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual
    address x.x.x.x/xx
    gateway x.x.x.x
    dns-search example.local
    dns-nameservers 208.67.222.222 208.67.220.220

NAME RESOLUTION

systemctl list-unit-files | grep resolv

#older releases
#systemctl status resolvconf
#systemctl stop resolvconf
#systemctl disable resolvconf

#artful  debian9/stretch  bionic
systemctl status systemd-resolved
systemctl stop systemd-resolved
systemctl disable systemd-resolved

#more shit seen on a bionic dedibox
systemctl stop bind9
systemctl disable bind9
systemctl status bind9-resolvconf

cd /etc/
ls -lhF resolv.conf*
mv resolv.conf resolv.conf.dist
cat > resolv.conf <<-EOF
search example.local
nameserver 208.67.222.222
nameserver 208.67.222.220
EOF
cat resolv.conf

and eventually

systemctl stop systemd-hostnamed.service
systemctl disable systemd-hostnamed.service

FIREWALLING

Eventually switch to Netfilter,

ufw disable

SSHD & SSH

TROUBLESHOOTING

In case you get,

RTNETLINK answers: File exists

while restarting networking, look at the logs and proceed against the relevant interface,

ip addr flush dev NETIF

Nethence | Pub | Lab | Pbraun | SNE Russia | xhtml