linux:networking:static_ip

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 /etc/netplan directory. There are two renderers: NetworkManager and networkd.
 +
 +**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, see netplan(5).
 +network:
 + version: 2
 + renderer: networkd
 + ethernets:
 +   ens33:
 +     dhcp4: yes
 +     dhcp6: yes
 +</code>
 +
 +<code ini Static configuration>
 +# This file describes the network interfaces available on your system
 +# For more information, see netplan(5).
 +network:
 + version: 2
 + renderer: networkd
 + ethernets:
 +   ens33:
 +     dhcp4: no
 +     dhcp6: no
 +     addresses: [192.168.1.2/24]
 +     gateway4: 192.168.1.1
 +     nameservers:
 +       addresses: [8.8.8.8,8.8.4.4]
 +</code>
 +
 +<code bash Apply changes>sudo netplan apply</code>
 +
 +===== Examples =====
 +<code javascript Multiple IP addresses and multiple gateways>
 +
 +
 +network:
 +  version: 2
 +  renderer: networkd
 +  ethernets:
 +    enp3s0:
 +     addresses:
 +       - 9.0.0.9/24
 +       - 10.0.0.10/24
 +       - 11.0.0.11/24
 +     #gateway4:    # unset, since we configure routes below
 +     routes:
 +       - to: 0.0.0.0/0
 +         via: 9.0.0.1
 +         metric: 100
 +       - to: 0.0.0.0/0
 +         via: 10.0.0.1
 +         metric: 100
 +       - to: 0.0.0.0/0
 +         via: 11.0.0.1
 +         metric: 100
 +</code>
 +<code javascript Wireless>
 +
 +
 +network:
 +  version: 2
 +  renderer: networkd
 +  wifis:
 +    wlp2s0b1:
 +      dhcp4: no
 +      dhcp6: no
 +      addresses: [192.168.0.21/24]
 +      gateway4: 192.168.0.1
 +      nameservers:
 +        addresses: [192.168.0.1, 8.8.8.8]
 +      access-points:
 +        "network_ssid_name":
 +          password: "**********"
 +</code>
 +<code javascript Static>
 +
 +
 +network:
 +  version: 2
 +  renderer: networkd
 +  ethernets:
 +    enp3s0:
 +      addresses:
 +        - 10.10.10.2/24
 +      gateway4: 10.10.10.1
 +      nameservers:
 +          search: [mydomain, otherdomain]
 +          addresses: [10.10.10.1, 1.1.1.1]
 +</code>
 +
 +
 +
 +
 +====== Version 16.04 and earlier ======
 +
 +
 +Edit network configuration file
 +<code>sudo vim /etc/network/interfaces</code>
 +
 +You fill find configuration something like this
 +<code>
 +# The primary network interface -- use DHCP to find our address
 +auto eth0
 +iface eth0 inet dhcp
 +</code>
 +
 +Change it to this
 +<code>
 +# 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
 +</code>
 +
 +And finally restart networking service
 +<code>sudo /etc/init.d/networking restart</code>
 +
 +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
 +<code>up route add -net 192.168.10.0 netmask 255.255.255.0 gw 192.168.180.1 dev eth0</code>
 +
 +And delete them 
 +<code>down route del -net 192.168.10.0 netmask 255.255.255.0 gw 192.168.180.1 dev eth0</code>
  • linux/networking/static_ip.txt
  • Last modified: 2019/10/31 09:05
  • by 127.0.0.1