Configure IP address, mask, gateway, and DNS in Ubuntu

Source: Internet
Author: User
Tags nameserver

I. Set IP addresses, masks, gateways, and DNS using commands

1. Set the IP address and subnet mask of the network adapter eth0: sudo ifconfig eth0 192.168.0.50 netmask 255.255.255.0
2. Set the gateway sudo route add default GW 192.168.0.1
3. Set DNS modification/etc/resolv. conf and add
Nameserver 8.8.8.8
Nameserver DNS address 2

II. Set the IP address, mask, gateway, and DNS by modifying the configuration file

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 limit 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 limit 255.0
network X. x. x. x
broadcast X. x. x. x
gateway X. x. 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.

From: http://hi.baidu.com/fcstom/blog/item/3e48a64e873d302caec3ab73.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.