Basic network Configuration under Ubuntu

Source: Internet
Author: User

Setting up a network is specifying an IP address and a DNS server:

The related configuration files under Ubuntu are:
/etc/network/interfaces and/etc/resolv.conf two files:

You can use the Man command: View the format description of both script files: [CPP] view plain copy wzb@ubuntu:~$ man interfaces wzb@ubuntu:~$ Mans resolv.conf

First, through the command: IFCONFIG-A view the system's network card.

In general, Eth0 and Lo are the first Ethernet network adapters and the NIC used for Local loop testing.

For eth0, there are the following ways to set up:

1. Configure network adapters by DHCP
Edit file/etc/network/interfaces: [plain] view plain copy sudo vi/etc/network/interfaces

Use the following line to replace the line about eth0: [plain] view Plain Copy # The primary network Interface-use DHCP to find we address auto eth0 iface eth0 inet DHCP


Use the following command to make the network settings effective: [plain] view plain copy sudo/etc/init.d/networking restart

Of course, you can also enter the following command directly under the command line to get the address [plain] view plain copy sudo dhclient eth0

2. Configure a static IP address for the network card
Edit file/etc/network/interfaces: [plain] view plain copy sudo vi/etc/network/interfaces

Use the following line to replace the line about eth0: [plain] view Plain Copy # 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

Change the above IP address and other information to yourself.

Use the following command to make the network settings effective: [plain] view plain copy sudo/etc/init.d/networking restart

3. Set a second IP address (virtual IP address)
Edit file/etc/network/interfaces: [plain] view plain copy sudo vi/etc/network/interfaces

Add the following line to the file: [plain] view plain copy auto eth0:1 iface eth0:1 inet static address 192.168.1.60 netmask 255. 255.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 gateway, according to your situation.

Use the following command to make the network settings effective: [plain] view plain copy sudo/etc/init.d/networking restart

4. Set host name (hostname)
Use the following command to view the host name of the current host: [plain] view plain copy Sudo/bin/hostname

Use the following command to set the host name of the current host: [plain] view plain copy sudo/bin/hostname newname

When the system starts, it reads the name of the host from the/etc/hostname.

For more information about setting host names,

You can use the Man command to view more details about hostname:
(Note: The hostname is both a command and a file, man hostname will get what we want?)

The answer is no, get is the manual Manual of command hostname, you can get the format of hostname script file in the following way.[Java] View Plain Copy wzb@ubuntu:~$ whatis hostname   hostname  (7)           - hostname resolution description   hostname  (1)          - show or set the system ' s  host name   wzb@ubuntu:~$ whereis hostname   hostname: /bin/ hostname          /etc/hostname           /usr/share/man/man7/hostname.7.gz               /usr/share/man/man1/hostname.1.gz   wzb@ubuntu:~$ whereis -m  hostname   hostname: /usr/share/man/man7/hostname.7.gz           /usr/share/man/man1/hostname.1.gz   wzb@ubuntu:~$ man  7  hostname  

5. Configure DNS
First, you can add some host names and IP addresses for these host names in the/etc/hosts, which is a simple static query using this machine.
To access the DNS server for querying, you need to set the/etc/resolv.conf file.
Assuming that the IP address of the DNS server is 8.8.8.8, then the contents of the/etc/resolv.conf file should be: [plain] view plain copy search google.com nameserver

The files are basically configured, and then use sudo/etc/init.d/networking start to make them effective!

(sudo ifup-a is also the/etc/network/interfaces file).
Use Ifconfig-a to see if you specified the address in the/etc/network/interfaces script file.
Finally ping to test your network bar: [CPP] view plain copy ping www.baidu.com

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.