configure_static_ip_address_ubuntu_server_22_04

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
configure_static_ip_address_ubuntu_server_22_04 [2023/06/20 11:43] – created wikiadminconfigure_static_ip_address_ubuntu_server_22_04 [2023/06/20 14:42] (current) wikiadmin
Line 2: Line 2:
  
 <code> <code>
-frank@nc3:~$ ifconfig+user@svr1:~$ ifconfig
 eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
-        inet 192.168.2.106  netmask 255.255.255.0  broadcast 192.168.2.255+        inet 192.168.1.95  netmask 255.255.255.0  broadcast 192.168.1.255
         inet6 fe80::d6ae:52ff:fecd:3bf8  prefixlen 64  scopeid 0x20<link>         inet6 fe80::d6ae:52ff:fecd:3bf8  prefixlen 64  scopeid 0x20<link>
         ether d4:ae:52:cd:3b:f8  txqueuelen 1000  (Ethernet)         ether d4:ae:52:cd:3b:f8  txqueuelen 1000  (Ethernet)
Line 22: Line 22:
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  
-frank@nc3:~$ ip +user@svr1:~$ cd /etc/netplan/ 
-Usage: ip [ OPTIONS ] OBJECT { COMMAND | help } +user@svr1:/etc/netplan$ ls -l
-       ip [ -force ] -batch filename +
-where  OBJECT := { address | addrlabel | fou | help | ila | ioam | l2tp | link | +
-                   macsec | maddress | monitor | mptcp | mroute | mrule | +
-                   neighbor | neighbour | netconf | netns | nexthop | ntable | +
-                   ntbl | route | rule | sr | tap | tcpmetrics | +
-                   token | tunnel | tuntap | vrf | xfrm } +
-       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] | +
-                    -h[uman-readable] | -iec | -j[son] | -p[retty] | +
-                    -f[amily] { inet | inet6 | mpls | bridge | link } | +
-                    -4 | -6 | -M | -B | -0 | +
-                    -l[oops] { maximum-addr-flush-attempts } | -br[ief] | +
-                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] | +
-                    -rc[vbuf] [size] | -n[etns] name | -N[umeric] | -a[ll] | +
-                    -c[olor]} +
-frank@nc3:~$ cd /etc/netplan/ +
-frank@nc3:/etc/netplan$ ls -l+
 total 4 total 4
 -rw-r--r-- 1 root root 115 Jun 18 18:43 00-installer-config.yaml -rw-r--r-- 1 root root 115 Jun 18 18:43 00-installer-config.yaml
-frank@nc3:/etc/netplan$ vim 00-installer-config.yaml +user@svr1:/etc/netplan$ vim 00-installer-config.yaml 
-frank@nc3:/etc/netplan$ ifconfig -a+user@svr1:/etc/netplan$ ifconfig -a
 eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
-        inet 192.168.2.106  netmask 255.255.255.0  broadcast 192.168.2.255+        inet 192.168.1.95  netmask 255.255.255.0  broadcast 192.168.1.255
         inet6 fe80::d6ae:52ff:fecd:3bf8  prefixlen 64  scopeid 0x20<link>         inet6 fe80::d6ae:52ff:fecd:3bf8  prefixlen 64  scopeid 0x20<link>
         ether d4:ae:52:cd:3b:f8  txqueuelen 1000  (Ethernet)         ether d4:ae:52:cd:3b:f8  txqueuelen 1000  (Ethernet)
Line 62: Line 46:
         TX packets 288  bytes 29450 (29.4 KB)         TX packets 288  bytes 29450 (29.4 KB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 +</code>
  
-frank@nc3:/etc/netplan$ cp -v 00-installer-config.yaml 00-installer-config.bak+Let's switch to /etc/netplan subdirectory path and perform a list command to see what is stored in the subdirectory. 
 + 
 +<code> 
 +user@svr1:$ cd /etc/netplan/ 
 +user@svr1:/etc/netplan$ ls 
 +user@svr1:/etc/netplan$ 00-installer-config.yaml 
 +</code> 
 + 
 +Then, before we edit the network configuration file, let's make a backup of the '00-installer-config.yaml' file and call it '00-installer-config.yaml-bak' just in case we need to restore it in the future to obtain a dynamic IP lease. 
 + 
 +<code> 
 +user@svr1:/etc/netplan$ cp -v 00-installer-config.yaml 00-installer-config.bak
 '00-installer-config.yaml' -> '00-installer-config.bak' '00-installer-config.yaml' -> '00-installer-config.bak'
 cp: cannot create regular file '00-installer-config.bak': Permission denied cp: cannot create regular file '00-installer-config.bak': Permission denied
-frank@nc3:/etc/netplan$ sudo cp -v 00-installer-config.yaml 00-installer-config.yaml-bak +user@svr1:/etc/netplan$ sudo cp -v 00-installer-config.yaml 00-installer-config.yaml-bak 
-[sudo] password for frank:+[sudo] password for user:
 '00-installer-config.yaml' -> '00-installer-config.yaml-bak' '00-installer-config.yaml' -> '00-installer-config.yaml-bak'
-frank@nc3:/etc/netplan$ ls+user@svr1:/etc/netplan$ ls
 00-installer-config.yaml  00-installer-config.yaml-bak 00-installer-config.yaml  00-installer-config.yaml-bak
-frank@nc3:/etc/netplan$ sudo vim 00-installer-config.yaml +user@svr1:/etc/netplan$ sudo vim 00-installer-config.yaml 
-frank@nc3:/etc/netplan$ vim 00-installer-config.yaml +</code> 
-frank@nc3:/etc/netplan$ frank@nc3:/etc/netplan$ ls+ 
 +Here is the original dhcp configuration for eno1. 
 + 
 +<code> 
 +# This is the network config written by 'subiquity' 
 +network: 
 +  ethernets: 
 +    eno1: 
 +      dhcp4: true 
 +  version: 2 
 +</code> 
 + 
 +Using Vim editor, here is how to configure the static IP.  
 + 
 +<code> 
 +$ sudo vi 00-installer-config.yaml 
 +</code> 
 + 
 +While within Vim, to the preceding lines of the original configuration, add an IP address, a net mask, and a default gateway. Replace the samples below with the appropriate static values (and you can use your own nameservers rather than Google's) as follows: 
 + 
 +<code> 
 +network: 
 +    ethernets: 
 +      en01: 
 +        addresses: 
 +          - 192.168.1.95/24 
 +        routes: 
 +          - to: default 
 +            via: 192.168.1.1 
 +        nameservers: 
 +          addresses: [8.8.8.8,8.8.4.4] 
 +        dhcp4: no 
 +    version: 2 
 +</code> 
 + 
 +Another author instead inserts the following content which varies only by two lines (renderer: networkd) and (nameservers): 
 + 
 +<code> 
 +$ sudo vi 00-installer-config.yaml 
 +# This is the network config written by 'subiquity' 
 +network: 
 +  renderer: networkd 
 +  ethernets: 
 +    ens33: 
 +      addresses: 
 +        - 192.168.1.95/24 
 +      nameservers: 
 +        addresses: [4.2.2.2, 8.8.8.8] 
 +      routes: 
 +        - to: default 
 +          via: 192.168.1.1 
 +  version: 2 
 +</code> 
 + 
 +<code> 
 +user@svr1:/etc/netplan$ vim 00-installer-config.yaml 
 +user@svr1:/etc/netplan$  
 +user@svr1:/etc/netplan$ ls
 00-installer-config.yaml  00-installer-config.yaml-bak 00-installer-config.yaml  00-installer-config.yaml-bak
-frank@nc3:/etc/netplan$ sudo netplan apply +</code> 
-[sudo] password for frank:+ 
 +After Saving the new static configuration using Vim (:w  :qs), then apply the changes to netplan as follows: 
 + 
 +<code> 
 +user@svr1:/etc/netplan$ sudo netplan apply 
 +[sudo] password for user:
 Failed to reload network settings: No such file or directory Failed to reload network settings: No such file or directory
 Falling back to a hard restart of systemd-networkd.service Falling back to a hard restart of systemd-networkd.service
-frank@nc3:/etc/netplan$ sudo netplan apply +user@svr1:/etc/netplan$ sudo netplan apply 
-frank@nc3:/etc/netplan$ ping -c 5 www.google.com+</code> 
 + 
 +Notice that there was an error (failed to load, then the system auto-performed a hard restart of systemd-neworkd.service). This may be the result of using the first example above rather than the second (containing the line 'renderer: networkd').  A re-run of 'sudo netplan apply' like above, there is silent application.  Maybe insert the renderer line and re-apply to netplan.  See if that is silently applied as well. 
 + 
 + 
 +Now test the static configuration by running ping, or whatever else may be useful. 
 + 
 +<code> 
 +user@svr1:/etc/netplan$ ping -c 5 www.google.com
 PING www.google.com (142.250.217.228) 56(84) bytes of data. PING www.google.com (142.250.217.228) 56(84) bytes of data.
 64 bytes from mia07s62-in-f4.1e100.net (142.250.217.228): icmp_seq=1 ttl=117 time=11.8 ms 64 bytes from mia07s62-in-f4.1e100.net (142.250.217.228): icmp_seq=1 ttl=117 time=11.8 ms
Line 91: Line 157:
 5 packets transmitted, 5 received, 0% packet loss, time 4006ms 5 packets transmitted, 5 received, 0% packet loss, time 4006ms
 rtt min/avg/max/mdev = 11.387/12.302/13.216/0.674 ms rtt min/avg/max/mdev = 11.387/12.302/13.216/0.674 ms
-frank@nc3:/etc/netplan$+user@svr1:/etc/netplan$ 
 +</code> 
 + 
 +Run ifconfig: 
 + 
 +<code> 
 +$ ifconfig 
 +eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 
 +        inet 192.168.1.95  netmask 255.255.255.0  broadcast 192.168.1.255 
 +        inet6 fe80::d6ae:52ff:fecd:3bf8  prefixlen 64  scopeid 0x20<link> 
 +        ether d4:ae:52:cd:3b:f8  txqueuelen 1000  (Ethernet) 
 +        RX packets 183111  bytes 149312474 (149.3 MB) 
 +        RX errors 0  dropped 88  overruns 0  frame 0 
 +        TX packets 47132  bytes 8346015 (8.3 MB) 
 +        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0 
 +        device interrupt 16 
 + 
 +lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536 
 +        inet 127.0.0.1  netmask 255.0.0.0 
 +        inet6 ::1  prefixlen 128  scopeid 0x10<host> 
 +        loop  txqueuelen 1000  (Local Loopback) 
 +        RX packets 374  bytes 38261 (38.2 KB) 
 +        RX errors 0  dropped 0  overruns 0  frame 0 
 +        TX packets 374  bytes 38261 (38.2 KB) 
 +        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 </code> </code>
configure_static_ip_address_ubuntu_server_22_04.1687261382.txt.gz · Last modified: 2023/06/20 11:43 by wikiadmin