Configure the IP address in Ubuntu Linux

Source: Internet
Author: User
Tags nameserver

I installed Ubuntu today but found that I cannot access the Internet. I started to troubleshoot the problem:

1. First, check whether the network connection is correct and whether the network cable used works properly.

2. Check whether the network card works properly. The detection method is as follows:

A. Ping 127.0.0.1

B. Ping the static gateway address

C. Ping the Host Name (hostname indicates the host name)

3. Check whether the NIC address is correctly configured. (The ifconfig command checks the NIC information of the local host and compares it with the DNS, default getway, and sever addresses to check whether the NIC address is correct)

My device has a problem in the third aspect. Then, modify the NIC configuration information and run the following command: (of course, you can use the graphic window. I only use it to learn about Linux)

1. Use commands to set the IP address of ubuntu

1. modify the configuration file blacklist. conf to disable IPv6:
Sudo VI/etc/modprobe. d/blacklist. conf
2. Add blacklist IPV6 at the end of the document and view the Modification result:
CAT/etc/modprobe. d/blacklist. conf
3. Set the IP address (set the IP address and subnet mask of the network adapter eth0)
Sudo ifconfig eth0 192.168.2.1 netmask 255.255.255.0
4. Set the Gateway
Sudo route add default GW 192.168.2.254
5. Set DNS modification to/etc/resolv. conf and add nameserver DNS address 1 and nameserver DNS address 2.
6. Restart the network service (if not, restart Ubuntu: sudo reboot ):
Sudo/etc/init. d/networking restart
7. view the current IP Address:
Ifconfig

2. directly modify the Ubuntu Linux configuration file

The Network Ubuntu Linux configuration file is:/etc/Network/interfaces
After it is enabled, you can set DHCP or manually set static IP addresses. In front of auto eth0, 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.2.1
Gateway 192.168.2.254
Netmask 255.255.255.0
# Network 192.168.2.0
# Broadcast 192.168.2.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 x. x
Netmask x. x
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.

5. Configure DNS in Ubuntu Linux
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.2.2, the content of the/etc/resolv. conf file should be:
Search chotim.com
Nameserver 192.168.2.2

6. Manually restart the network service:
Sudo/etc/init. d/networking restart

Of course, Ubuntu has a graphical interface, so the preceding address settings can also be completed by setting like windows. In the upper part of the window, system-> preference should find the corresponding configuration options; in addition, it is inconvenient to modify the VI command when you use the command line to modify the configuration file. Therefore, you can use gedit to edit the configuration file.

(Original address: Http://www.cnblogs.com/empire/archive/2011/01/10/1931877.html)

I installed Ubuntu today but found that I cannot access the Internet. I started to troubleshoot the problem:

1. First, check whether the network connection is correct and whether the network cable used works properly.

2. Check whether the network card works properly. The detection method is as follows:

A. Ping 127.0.0.1

B. Ping the static gateway address

C. Ping the Host Name (hostname indicates the host name)

3. Check whether the NIC address is correctly configured. (The ifconfig command checks the NIC information of the local host and compares it with the DNS, default getway, and sever addresses to check whether the NIC address is correct)

My device has a problem in the third aspect. Then, modify the NIC configuration information and run the following command: (of course, you can use the graphic window. I only use it to learn about Linux)

1. Use commands to set the IP address of ubuntu

1. modify the configuration file blacklist. conf to disable IPv6:
Sudo VI/etc/modprobe. d/blacklist. conf
2. Add blacklist IPV6 at the end of the document and view the Modification result:
CAT/etc/modprobe. d/blacklist. conf
3. Set the IP address (set the IP address and subnet mask of the network adapter eth0)
Sudo ifconfig eth0 192.168.2.1 netmask 255.255.255.0
4. Set the Gateway
Sudo route add default GW 192.168.2.254
5. Set DNS modification to/etc/resolv. conf and add nameserver DNS address 1 and nameserver DNS address 2.
6. Restart the network service (if not, restart Ubuntu: sudo reboot ):
Sudo/etc/init. d/networking restart
7. view the current IP Address:
Ifconfig

2. directly modify the Ubuntu Linux configuration file

The Network Ubuntu Linux configuration file is:/etc/Network/interfaces
After it is enabled, you can set DHCP or manually set static IP addresses. In front of auto eth0, 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.2.1
Gateway 192.168.2.254
Netmask 255.255.255.0
# Network 192.168.2.0
# Broadcast 192.168.2.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 x. x
Netmask x. x
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.

5. Configure DNS in Ubuntu Linux
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.2.2, the content of the/etc/resolv. conf file should be:
Search chotim.com
Nameserver 192.168.2.2

6. Manually restart the network service:
Sudo/etc/init. d/networking restart

Of course, Ubuntu has a graphical interface, so the preceding address settings can also be completed by setting like windows. In the upper part of the window, system-> preference should find the corresponding configuration options; in addition, it is inconvenient to modify the VI command when you use the command line to modify the configuration file. Therefore, you can use gedit to edit the configuration file.

(Original address: Http://www.cnblogs.com/empire/archive/2011/01/10/1931877.html)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.