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.