Configure network commands in Ubuntu

Source: Internet
Author: User

Taking eth0 as an Example


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


Of course, you can also enter the following command under 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,
# Use static to find our address
Auto eth0
Iface eth0 Inet static
Address 192.168.1.98
Gateway 192.168.1.1
Netmask 255.255.255.0
Network 192.168.1.0
Broadcast 192.168.1.255


Run the following command to make the network settings take effect:

Sudo/etc/init. d/networking restart

Note:After it takes effect, you need to configure DNS before you can access the Internet (step 5)

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 and IP addresses corresponding to these host names in/etc/hosts.

To access the DNS server for query, you need to set the/etc/resolv. conf file.


For example, assume that the IP address of the DNS server is 192.168.1.1.

Edit the file:/etc/hosts

Sudo VI/etc/hosts


The Edit content is as follows:

Nameserver 192.168.1.1

Alternatively, edit/etc/resolv. conf and add the following content:

Sudo VI/etc/resolv. conf

Run the following command to make the network settings take effect:

Sudo/etc/init. d/networking restart

Recommendation reference:

Http://www.ubuntugeek.com/ubuntu-networking-configuration-using-command-line.html.

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.