Original article link
Use the command to set the IP address of ubuntu
New Ubuntu is installed. Although the IP address and gateway have been set in the graphic interface, they cannot access the Internet.
A friend warned that it may be a setup problem. Try setting the command line. So I searched for how to set it, and the result was actually successful.
The details are as follows:
1. to check whether the connection is available, ping the gateway using the ping command.
At the beginning, it is always true That unreachable
2. Set IP
Sudo ifconfig eth0 133.133.133.190 netmask 255.255.255.0
In this case, the IP address and subnet mask of the eth0 NIC are set.
3. Set the gateway sudo route add default GW 133.133.133.40
4. You can ping the gateway.
5. Set DNS modification/etc/resolv. conf and add
Nameserver DNS address 1
Nameserver DNS address 2
Complete.
After this setting, it seems that the IP address will change again at next boot.
1. Use commands to set the IP address of ubuntu
1. Set IP
Sudo ifconfig eth0 203.171.239.155 netmask has been released successfully
In this case, the IP address and subnet mask of the eth0 NIC are set.
2. Set the gateway sudo route add default GW 203.171.239.129
3. Set DNS modification/etc/resolv. conf, and add nameserver DNS address 1 nameserver DNS address 2 to it.
However, after this setting, it seems that the IP address does not exist at the next boot.
2. directly modify the system configuration file
The Ubuntu network configuration file is:/etc/Network/interfaces
Ubuntu Command Line Network Configuration Modification Method
/Etc/Network/interfaces
After it is enabled, you can set DHCP or manually set static IP addresses. Auto eth0 in front to enable automatic Nic mounting.
1. Configure the NIC in DHCP Mode
Edit the file/etc/Network/interfaces:
Sudo VI/etc/Network/interfaces
Replace eth0 with the following rows:
# The primary network interface-use DHCP to find our address
Auto eth0
Iface eth0 Inet DHCP
Run the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart
You can also enter the following command in the command line to obtain the address.
Sudo dhclient eth0
2. configure a static IP address for the NIC
Edit the file/etc/Network/interfaces:
Sudo VI/etc/Network/interfaces
Replace eth0 with the following rows: # the primary network interface
Auto eth0
Iface eth0 Inet static
Address 192.168.3.90
Gateway 192.168.3.1
Netmask 255.255.255.0
# Network 192.168.3.0
# Broadcast 192.168.3.255
Replace the preceding IP address and other information with your own. Use the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart
3. Set the second IP address (virtual IP address)
Edit the file/etc/Network/interfaces:
Sudo VI/etc/Network/interfaces
Add the following lines to the file:
Auto eth0: 1
Iface eth0: 1 Inet static
Address 192.168.1.60
Netmask 255.255.255.0
Network x. x
Broadcast x. x
Gateway x. x
Fill in all information such as address, netmask, network, broadcast, and gateways according to your situation.
Run the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart
4. Set Host Name (hostname)
Run the following command to view the Host Name of the current host:
Sudo/bin/hostname
Run the following command to set the Host Name of the current host:
Sudo/bin/hostname newname
When the system starts, it reads the host name from/etc/hostname.
For more information about setting host names, visit here
5. Configure DNS
First, you can add some host names to/etc/hosts and the IP addresses corresponding to these host names. This is a simple static query on the local machine.
To access the DNS server for query, you need to set the/etc/resolv. conf file.
If the IP address of the DNS server is 192.168.3.2, the content of the/etc/resolv. conf file should be:
Search test.com
Nameserver 192.168.3.2
/Etc/Network/interfaces
After it is enabled, you can set DHCP or manually set static IP addresses. Auto eth0 in front to enable automatic Nic mounting.
1. Configure the NIC in DHCP Mode
Edit the file/etc/Network/interfaces:
Sudo VI/etc/Network/interfaces
Replace eth0 with the following rows:
# The primary network interface-use DHCP to find our address
Auto eth0
Iface eth0 Inet DHCP
Run the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart
You can also enter the following command in the command line to obtain the address.
Sudo dhclient eth0
2. configure a static IP address for the NIC
Edit the file/etc/Network/interfaces:
Sudo VI/etc/Network/interfaces
Replace eth0 with the following rows: # the primary network interface
Auto eth0
Iface eth0 Inet static
Address 192.168.3.90
Gateway 192.168.3.1
Netmask 255.255.255.0
# Network 192.168.3.0
# Broadcast 192.168.3.255
Replace the preceding IP address and other information with your own. Use the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart
3. Set the second IP address (virtual IP address)
Edit the file/etc/Network/interfaces:
Sudo VI/etc/Network/interfaces
Add the following lines to the file:
Auto eth0: 1
Iface eth0: 1 Inet static
Address 192.168.1.60
Netmask 255.255.255.0
Network x. x
Broadcast x. x
Gateway x. x
Fill in all information such as address, netmask, network, broadcast, and gateways according to your situation.
Run the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart
4. Set Host Name (hostname)
Run the following command to view the Host Name of the current host:
Sudo/bin/hostname
Run the following command to set the Host Name of the current host:
Sudo/bin/hostname newname
When the system starts, it reads the host name from/etc/hostname.
For more information about setting host names, visit here
5. Configure DNS
First, you can add some host names to/etc/hosts and the IP addresses corresponding to these host names. This is a simple static query on the local machine.
To access the DNS server for query, you need to set the/etc/resolv. conf file.
If the IP address of the DNS server is 192.168.3.2, the content of the/etc/resolv. conf file should be:
Search test.com
Nameserver 192.168.3.2
Solve the Problem of restarting DNS in Ubuntu
By wynlchae Release Date: Views: 256 from: http://www.linuxdiyf.com
Set static IP in Ubuntu, "Main Menu", "system", "system management", and "network", delete the original DNS in "DNS", and fill in the static DNS server, however, it will be restored after the restart, and it will be reset again after the next boot.
First backup:
Sudo CP/etc/resolv. CONF/etc/resolv. conf. Bak
Edit
Sudo gvim/etc/dhcp3/dhclient. conf
Add the following lines to the end, that is, the two DNS servers.
Prepend domain-name-servers 208.67.222.222, 208.67.220.220; # Fill in the two servers based on their own DNS.