no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | linux:networking:static_ip [2019/10/31 09:05] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Static network IP on Ubuntu server ====== | ||
| + | Configuring IP address on Ubuntu server without using any tools other than a text editor | ||
| + | ====== Version 18.04 ====== | ||
| + | The new interfaces configuration file now lives in the / | ||
| + | |||
| + | **NetworkManager** renderer is mostly used on desktop computers and **networkd** on servers. If you want NetworkManager to control the network interfaces, use NetworkManager as the renderer, otherwise use networkd. | ||
| + | |||
| + | When you use NetworkManager as the renderer, you will use the NetworkManager GUI to manage the interfaces. | ||
| + | |||
| + | <code javascript DHCP sample file using networkd> | ||
| + | # This file describes the network interfaces available on your system | ||
| + | # For more information, | ||
| + | network: | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | <code ini Static configuration> | ||
| + | # This file describes the network interfaces available on your system | ||
| + | # For more information, | ||
| + | network: | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | <code bash Apply changes> | ||
| + | |||
| + | ===== Examples ===== | ||
| + | <code javascript Multiple IP addresses and multiple gateways> | ||
| + | |||
| + | |||
| + | network: | ||
| + | version: 2 | ||
| + | renderer: networkd | ||
| + | ethernets: | ||
| + | enp3s0: | ||
| + | | ||
| + | - 9.0.0.9/24 | ||
| + | - 10.0.0.10/ | ||
| + | - 11.0.0.11/ | ||
| + | # | ||
| + | | ||
| + | - to: 0.0.0.0/0 | ||
| + | via: 9.0.0.1 | ||
| + | | ||
| + | - to: 0.0.0.0/0 | ||
| + | via: 10.0.0.1 | ||
| + | | ||
| + | - to: 0.0.0.0/0 | ||
| + | via: 11.0.0.1 | ||
| + | | ||
| + | </ | ||
| + | <code javascript Wireless> | ||
| + | |||
| + | |||
| + | network: | ||
| + | version: 2 | ||
| + | renderer: networkd | ||
| + | wifis: | ||
| + | wlp2s0b1: | ||
| + | dhcp4: no | ||
| + | dhcp6: no | ||
| + | addresses: [192.168.0.21/ | ||
| + | gateway4: 192.168.0.1 | ||
| + | nameservers: | ||
| + | addresses: [192.168.0.1, | ||
| + | access-points: | ||
| + | " | ||
| + | password: " | ||
| + | </ | ||
| + | <code javascript Static> | ||
| + | |||
| + | |||
| + | network: | ||
| + | version: 2 | ||
| + | renderer: networkd | ||
| + | ethernets: | ||
| + | enp3s0: | ||
| + | addresses: | ||
| + | - 10.10.10.2/ | ||
| + | gateway4: 10.10.10.1 | ||
| + | nameservers: | ||
| + | search: [mydomain, otherdomain] | ||
| + | addresses: [10.10.10.1, | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ====== Version 16.04 and earlier ====== | ||
| + | |||
| + | |||
| + | Edit network configuration file | ||
| + | < | ||
| + | |||
| + | You fill find configuration something like this | ||
| + | < | ||
| + | # The primary network interface -- use DHCP to find our address | ||
| + | auto eth0 | ||
| + | iface eth0 inet dhcp | ||
| + | </ | ||
| + | |||
| + | Change it to this | ||
| + | < | ||
| + | # The primary network interface | ||
| + | auto eth0 | ||
| + | iface eth0 inet static | ||
| + | address 192.168.1.2 | ||
| + | gateway 192.168.1.1 | ||
| + | netmask 255.255.255.0 | ||
| + | network 192.168.1.0 | ||
| + | broadcast 192.168.1.255 | ||
| + | dns-nameservers 8.8.8.8 8.8.4.4 | ||
| + | </ | ||
| + | |||
| + | And finally restart networking service | ||
| + | < | ||
| + | |||
| + | You should be able to ping the host on the new IP address | ||
| + | |||
| + | If you need to add static routes, you can do it here by adding the lines | ||
| + | < | ||
| + | |||
| + | And delete them | ||
| + | < | ||