====== Static IP Address ======
See also **[[https://www.techwizcr.com/remove-netplan-on-ubuntu-18-04/linux/|Remove Netplan]]**
===== NetworkManager =====
nmcli con show
nmcli con mod "Wired connection 1" ipv4.method manual \
ipv4.addr 192.168.100.3/24 \
ipv4.gateway 192.168.100.1 \
ipv4.dns 192.168.100.1,8.8.8.8,8.8.4.4 \
connection.id "Office LAN"
nmcli con up "Office LAN"
===== Netplan =====
https://netplan.io/examples/
https://blog.ubuntu.com/2017/07/05/quick-and-easy-network-configuration-with-netplan
https://blog.ubuntu.com/2017/12/01/ubuntu-bionic-netplan
:!: **Indentation** is very important!
:!: We use ''netplan'' and ''networkd'' for network configuration.
:!: YAML files can be **renamed**.
* bonds
* bridges
* vlans
* standalone network interfaces
* static addresses
* DHCP addresses
==== Regenerate and Reapply After Editing ====
sudo netplan --debug generate
sudo netplan --debug apply
==== Ubuntu 18/20/22 (LACP Bond) ====
network:
version: 2
ethernets:
enp0s8:
dhcp4: no
enp0s9:
dhcp4: no
bonds:
bond0:
interfaces: [enp0s8, enp0s9]
addresses: [10.1.1.19/24]
routes:
- to: default
via: 10.1.1.1
nameservers:
search: [internal.domain, domain]
addresses: [10.1.1.20, 10.1.1.21]
parameters:
mode: 802.3ad
transmit-hash-policy: layer3+4
mii-monitor-interval: 1
==== Ubuntu 18/20/22 (Static) ====
sudo vi /etc/netplan/50-cloud-init.yaml
To suppress (or define) the default IPv6 ''link-local'' address (''fe80::''), add this to the interface definition (same indentation as ''addresses:''):
''link-local: []''
Example:
network:
ethernets:
eth0:
addresses: [10.1.1.17/24]
routes:
- to: 0.0.0.0/0
via: 10.0.0.1
nameservers:
addresses: [10.1.1.20,10.1.1.21]
eth1:
addresses: [10.1.9.17/24]
mtu: 9000
version: 2
==== Troubleshooting ====
If you have trouble with netplan, try removing these files, then regenerate and reapply:
* Extra addresses
* Extra routes
rm /run/network/dynamic-interfaces
rm /run/netplan/eth0.yaml
rm /run/net-eth0.conf
===== Ubuntu 16.04 =====
Remove some unnecessary junk from your server, then configure:
apt-get purge network-manager resolvconf rdnssd
rm -f /etc/resolv.conf
sudo vim /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.1.30
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-search sonoracomm.local
dns-nameservers 8.8.8.8 8.8.4.4
===== Hostname =====
hostname short-hostname
hostnamectl set-hostname fqdn-host-name
sudo vim /etc/hosts
192.168.1.30 hostname.example.com hostname
echo new-hostname > /etc/hostname
hostname
hostname -f
:!: See below to **[[networking:linux:static_ip_addr#name_resolution|configure name resolution]]** before rebooting.
sudo reboot
===== CentOS =====
**CentOS 8**: https://www.howtoforge.com/how-to-configure-a-static-ip-address-on-centos-8/
You can use the ncurses-based utility 'system-config-network-tui', but it installs quite a few dependencies for a minimal system. You may have to install it if it's not already installed:
yum install system-config-network-tui
yum remove NetworkManager
system-config-network-tui
or by manually editing configuration files for more control:
vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=shorthostname
GATEWAY=192.168.1.1
vi /etc/sysconfig/network-scripts/ifcfg-eth0
NM_CONTROLLED=no
DEVICE=eth0
BOOTPROTO=none
IPADDR=192.168.1.30
NETMASK=255.255.255.0
ONBOOT=yes
===== Restart Networking =====
==== CentOS ====
systemctl stop network.service && systemctl start network.service && systemctl enable network.service
==== Ubuntu ====
systemctl restart NetworkManager.service
===== Check Networking =====
ifconfig | more
route -n
If you have problems, you may want to remove other configuration files that can confuse things. While there are legitimate reasons to have files in these folders, they will probably just complicate simple networking configurations:
rm /etc/sysconfig/networking/devices/*
rm /etc/sysconfig/networking/profiles/default/*
service network restart
===== Hostname =====
:!: If the hostname reverts back to the old hostname **after a reboot**:
sudo sed -i '/preserve_hostname: false/c\preserve_hostname: true' /etc/cloud/cloud.cfg && sudo hostnamectl set-hostname shorthostname
Set the hostname:
hostnamectl set-hostname
hostnamectl status
systemctl restart systemd-hostnamed
cat /etc/hostname
vi /etc/hosts
192.168.1.30 hostname.example.com hostname
systemctl stop network.service && systemctl start network.service && systemctl enable network.service
hostname
hostname -f
:!: If both ''hostname'' commands show the **FQDN**, **try rebooting** before troubleshooting further.
If you continue to have problems, you may want to remove other configuration files that can confuse things. While there are legitimate reasons to have files in these folders, they will probably just complicate simple networking configurations:
rm /etc/sysconfig/networking/devices/*
rm /etc/sysconfig/networking/profiles/default/*
service network restart
===== Name Resolution =====
systemd-resolve --status
resolvectl status
https://www.shellhacks.com/setup-dns-resolution-resolvconf-example/
:!: Applies to **Debian and Enterprise Linux** distros.
:!: Purge the ''resolvconf'' package first!
:!: If you have trouble saving the edited file, you may need to **delete a 'leftover' symlink** created by the (now removed) ''resolvconf'' package.
vi /etc/resolv.conf
nameserver 192.168.0.2
nameserver 8.8.8.8
domain example.com
search example.com local.lan
==== Ubuntu 18.04 LTS ====
Disable ''systemd-resolved'' and use ''/etc/resolv.conf'':
vi /etc/systemd/resolved.conf
DNSStubListener=no
systemctl stop systemd-resolved
systemctl status systemd-resolved
vim /etc/resolv.conf
reboot
===== Grub Boot Delay =====
sed -i -e 's/GRUB_TIMEOUT=0/GRUB_TIMEOUT=5/g' /etc/default/grub
update-grub