Ubuntu-Network Management-Static IP
- 1.Ubuntu14.04LTS
- 1. Version Information
- 2. Static IP configuration
- 1. Get current network information
- 2. Modify / etc / network / interfaces
- 3. Modify /etc/NetworkManager/NetworkManager.conf
- 4. Restart
- 3. Test
- 2.Ubuntu16.04LTS
- 1. Version Information
- 2. Static IP configuration
- 1. Get current network information
- 2. Modify / etc / network / interfaces
- 3. Modify /etc/NetworkManager/NetworkManager.conf
- 4. Modify /etc/resolvconf/resolv.conf.d/base
- 5. Restart the network
- 3. Test
- 3.Ubuntu18.04LTS
1.Ubuntu14.04LTS
1. Version Information
cat /proc/version
Linux version 4.4.0-148-generic (buildd@lgw01-amd64-014) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4) ) #174~14.04.1-Ubuntu SMP Thu May 9 08:17:37 UTC 2019
2. Static IP configuration
1. Get current network information
1. Get Gateway Information
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.234.2 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.234.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
2. Obtain IP information
ifconfig
docker0 Link encap:Ethernet HWaddr 02:42:91:d4:70:77
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth0 Link encap:Ethernet HWaddr 00:0c:29:58:0d:f8
inet addr:192.168.234.100 Bcast:192.168.234.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe58:df8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:803 errors:0 dropped:0 overruns:0 frame:0
TX packets:814 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:250601 (250.6 KB) TX bytes:103036 (103.0 KB)
Interrupt:19 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:123 errors:0 dropped:0 overruns:0 frame:0
TX packets:123 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:8881 (8.8 KB) TX bytes:8881 (8.8 KB)
If you cannot execute the ifconfig command, you need to install the net-tools tool
sudo apt install -y net-tools
Network card | IP( inet addr) | Broadcast address (Bcast) | Mask |
---|---|---|---|
eth0 | 192.168.234.100 | 192.168.234.255 | 255.255.255.0 |
Need to be modified to:
Network card | IP( inet addr) | Broadcast address (Bcast) | Mask |
---|---|---|---|
eth0 | 192.168.234.60 | 192.168.234.255 | 255.255.255.0 |
2. Modify / etc / network / interfaces
sudo vim /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
Modify as follows:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.234.60
netmask 255.255.255.0
gateway 192.168.234.2
dns-nameservers 114.114.114.114
dns-nameservers can also not fill in here, you need to add a nameserver 114.114.114.114 in: sudo vim /etc/resolv.conf, it is more troublesome, so it is more convenient to add dns-nameservers 114.114.114.114 directly here
3. Modify /etc/NetworkManager/NetworkManager.conf
sudo vim /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq
[ifupdown]
managed=false
Modify [managed = true]:
[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq
[ifupdown]
managed=true
4. Restart
Why not restart the network, but restart the machine?
Because execution: sudo /etc/init.d/networking restart often does not work
sudo reboot
3. Test
1. Network Information Test
ifconfig
2. Networking test
curl -X GET "http://www.baidu.com"
2.Ubuntu16.04LTS
1. Version Information
cat /proc/version
Linux version 4.15.0-96-generic (buildd@lgw01-amd64-007) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)) #97~16.04.1-Ubuntu SMP Wed Apr 1 03:03:31 UTC 2020
2. Static IP configuration
1. Get current network information
1. Get Gateway Information
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.234.2 0.0.0.0 UG 100 0 0 ens33
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 ens33
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.234.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
2. Obtain IP information
ifconfig
docker0 Link encap:Ethernet HWaddr 02:42:a8:77:b0:51
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
ens33 Link encap:Ethernet HWaddr 00:0c:29:c5:27:c8
inet addr:192.168.234.129 Bcast:192.168.234.255 Mask:255.255.255.0
inet6 addr: fe80::a35e:af29:2935:9820/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2311 errors:0 dropped:0 overruns:0 frame:0
TX packets:618 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1447686 (1.4 MB) TX bytes:54078 (54.0 KB)
Interrupt:19 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:290 errors:0 dropped:0 overruns:0 frame:0
TX packets:290 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25128 (25.1 KB) TX bytes:25128 (25.1 KB)
If you cannot execute the ifconfig command, you need to install the net-tools tool
sudo apt install -y net-tools
Network card | IP( inet addr) | Broadcast address (Bcast) | Mask |
---|---|---|---|
ens33 | 192.168.234.129 | 192.168.234.255 | 255.255.255.0 |
Need to be modified to:
Network card | IP( inet addr) | Broadcast address (Bcast) | Mask |
---|---|---|---|
ens33 | 192.168.234.61 | 192.168.234.255 | 255.255.255.0 |
2. Modify / etc / network / interfaces
sudo vim /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
Modify as follows:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto ens33
iface ens33 inet static
address 192.168.234.61
netmask 255.255.255.0
gateway 192.168.234.2
3. Modify /etc/NetworkManager/NetworkManager.conf
sudo vim /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq
[ifupdown]
managed=false
Modify [managed = true]:
[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq
[ifupdown]
managed=true
4. Modify /etc/resolvconf/resolv.conf.d/base
sudo vim /etc/resolvconf/resolv.conf.d/base
Add to:
nameserver 114.114.114.114
5. Restart the network
sudo /etc/init.d/networking restart
If the test fails, restart the computer directly
sudo reboot
3. Test
1. Network Information Test
ifconfig
2. Networking test
curl -X GET "http://www.baidu.com"
3.Ubuntu18.04LTS
1. Version Information
cat /proc/version
Linux version 5.3.0-46-generic (buildd@lcy01-amd64-013) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #38~18.04.1-Ubuntu SMP Tue Mar 31 04:17:56 UTC 2020
2. Static IP configuration
1. Get current network information
1. Get Gateway Information
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.234.2 0.0.0.0 UG 100 0 0 ens33
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 ens33
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.234.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
2. Obtain IP information
ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:a2:55:db:1a txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.234.133 netmask 255.255.255.0 broadcast 192.168.234.255
inet6 fe80::20c:29ff:fe1e:a361 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:1e:a3:61 txqueuelen 1000 (Ethernet)
RX packets 2567 bytes 320945 (320.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 434 bytes 55474 (55.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 19 base 0x2000
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 261 bytes 22051 (22.0 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 261 bytes 22051 (22.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
If you cannot execute the ifconfig command, you need to install the net-tools tool
sudo apt install -y net-tools
Network card | IP( inet addr) | Broadcast address (Bcast) | Mask |
---|---|---|---|
ens33 | 192.168.234.133 | 192.168.234.255 | 255.255.255.0 |
Need to be modified to:
Network card | IP( inet addr) | Broadcast address (Bcast) | Mask |
---|---|---|---|
ens33 | 192.168.234.62 | 192.168.234.255 | 255.255.255.0 |
2. Modify /etc/netplan/01-network-manager-all.yaml
sudo vim /etc/netplan/01-network-manager-all.yaml
Modify as follows:
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
ens33:
dhcp4: no
dhcp6: no
addresses: [192.168.234.62/24]
gateway4: 192.168.234.2
nameservers:
addresses: [114.114.114.114,8.8.8.8]
3. Application modification
sudo netplan apply
If the test fails, restart the computer directly
sudo reboot
3. Test
1. Network Information Test
ifconfig
2. Networking test
curl -X GET "http://www.baidu.com"