Sources of problems
Sometimes we need to cooperate with colleagues or share resources with each other (more for the convenience of cooperation under the LAN, mutual need to know each other's IP addresses) in the working network environment, and prevent the intermittent network problems caused by IP address conflicts. We want to fix the IP address of our computer.
II. Solutions
- Search a lot of online solutions, see a lot of modifications or editing / etc/network/interfaces file, as follows:
You can see that 1992.168.16.178 is the IP address I want to fix, but when I restart the computer or I turn on the next day at work, it changed again, and I fixed an IP before: 192.168.16.119, but 119 seems to have conflict with other computer IP, so I can't access the Internet intermittently.luoxi@luoxi-linux:~$ cat /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto enp1s0 iface enp1s0 inet static address 192.168.16.178 netmask 255.255.255.0 gateway 192.168.16.1 ns-nameserver 172.16.1.4
- Then, I thought that since every reboot or boot is 119 IP, it must be fixed somewhere, and I need to manually change it. Finally, I found this tool: netplan, good ubuntu 16 and 18 all have this tool, and then how to do it, see below:
First look at the network card information:
Next, let's look at netplan-h:enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.16.178 netmask 255.255.255.0 broadcast 192.168.16.255 inet6 fe80::8eec:4bff:fe6a:1c62 prefixlen 64 scopeid 0x20<link> ether 8c:ec:4b:6a:1c:62 txqueuelen 1000 (Ethernet) RX packets 235831 bytes 225411841 (225.4 MB) RX errors 0 dropped 2 overruns 0 frame 0 TX packets 161560 bytes 22774156 (22.7 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
You can see that under generate there is / etc/netplan/*.yaml, which is where we are looking. My configuration is as follows:luoxi@luoxi-linux:~$ netplan -h usage: /usr/sbin/netplan [-h] [--debug] ... Network configuration in YAML optional arguments: -h, --help show this help message and exit --debug Enable debug messages Available commands: help Show this help message apply Apply current netplan config to running system generate Generate backend specific configuration files from /etc/netplan/*.yaml ip Retrieve IP information from the system try Try to apply a new netplan config to running system, with automatic rollback
Finally, according to the above method combined with your specific network card information, modify the *. yaml configuration file to save, and then execute the command netplan application to complete the fixed IP effect. Restart the computer to take effect!luoxi@luoxi-linux:~$ cat /etc/netplan/50-cloud-init.yaml network: ethernets: enp1s0: addresses: - 192.168.16.178/24 gateway4: 192.168.16.1 nameservers: addresses: [172.16.1.14, 172.16.1.228] dhcp4: false optional: false version: 2
III. OTHER
- If the above method does not work, please refer to more netplan fixed ip address settings, and check the configuration of dns, gateway and other ip is correct;
- 50-cloud-init.yaml configuration file name is only my configuration file name. Please view the specific file according to your Ubuntu or other versions of linux and configure it into effect, flexible and flexible.
- Not all-inclusive, if you have any questions, please leave a message. Thank you!