first step:
Configure a static IP address:
Open the /etc/network/interfaces file, the content is
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
The above means that DHCP is used to allocate IP by default. If you want to specify a static IP, you need to modify the following
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static*******Defined as static IP
address 192.168.2.29*******IP address to be set
netmask 255.255.255.0*******Subnet mask
gateway 192.168.2.1*******Gateway (routing address)
Then save this file
The second step:
Manually set up DNS server
Open the file /etc/resolv.conf and set the content as follows
nameserver 192.168.2.1******Gateway (same as above)
third step:
Note: After restarting Ubuntu, I found that the Internet cannot be accessed. The problem appears in /etc/resolv.conf. After restarting, the dns configured in this file is automatically modified to the default value. So you need to permanently modify the DNS. The method is
Open the file /etc/resolvconf/resolv.conf.d/base and write the following content:
nameserver 192.168.2.1
nameserver 202.106.0.20
the fourth step:
Restart the network service to make it effective, the command is:
/etc/init.d/networking restart
(My personal experience is: restarting this service is invalid, or restarting the system is awesome)
Recommended Posts