First edit the/etc/network/interfaces file and execute the following command in the terminal
sudo vi/etc/network/interfaces
To configure a static IP address
The contents to be edited are as follows:
Auto Eth0 # #自动启用第一块网卡
ifconf eth0 inet Static
Address 192.168.1.2 # #IP地址
netmask 255.255.255.0 # #子网掩码
Gateway 192.168.1.1 # #网关
You can also do this:
Enter in the terminal
sudo ifconfig address 192.168.1.2 # #设置IP
sudo ifconfig netmask 255.255.255.0# #设置子网掩码
sudo ifconfig Gateway 192.158.1.1 # #设置网关
And then just configure DNS
sudo vi/etc/resolv.conf
Add Content:
NameServer 61.177.7.1
Configuring gateways
sudo route add default GW 192.168.0.1
Restart Network configuration
/etc/init.d/networking restart
The network configuration command under Linux is ifconfig similar to the ipconfig in the Windows command line. You can use the Ifconfig command to configure and view the configuration of network interfaces. For example: (1) Configure the IP address of the eth0 while activating the device. Ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
(2) Configure the IP address of the eth0 alias device eth0:1 and add routes. Ifconfig eth0 192.168.1.3 Route add–host 192.168.1.3 Dev eth0:1
(3) activating the device. Ifconfig eth0 up
(4) Disable the device. Ifconfig eth0 Down
(5) View the configuration of the specified network interface. Ifconfig eth0
(6) View all network interface configurations. Ifconfig
2, Route can use the route command to configure and view the configuration of the kernel routing table. For example: (1) A route added to the host. Route add–host 192.168.1.2 Dev eth0:0 Route add–host 10.20.30.148 GW 10.20.30.40
(2) Routes added to the network. Route add–net 10.20.30.40 netmask 255.255.255.248 eth0 Route add–net 10.20.30.48 netmask 255.255.255.248 GW 10.20.30.41 Route Add–net 192.168.1.0/24 eth1
(3) Add a default gateway. Route add default GW 192.168.1.1
(4) View the configuration of the kernel routing table. Route
(5) Delete route. Route del–host 192.168.1.2 Dev eth0:0 Route del–host 10.20.30.148 GW 10.20.30.40 Route del–net 10.20.30.40 255. Eth0 Route del–net 10.20.30.48 netmask 255.255.255.248 GW 10.20.30.41 Route del–net 192.168.1.0/24 eth1 rout 255.255.248 E del default GW 192.168.1.1
For 1 and 22 points, you can use the following statement: Ifconfig eth0 172.16.19.71 netmask 255.255.255.0 Route 0.0.0.0 GW 172.16.19.254 Service Network restart 3, traceroute can use the traceroute command to display packets to the destination host through the route. For example: Traceroute x
4. Ping can use the ping command to test the connectivity of the network. For example: Ping x ping–c 4 192.168.1.12
5, Netstat can use the netstat command to display network status information. For example: (1) Display network interface status information. Netstat–i
(2) Displays the sockets of all servers in the monitor and the program information that is using the socket. Netstat–lpe
(3) Display the kernel routing table information. Netstat–r NETSTAT–NR
(4) Displays the connection status of the TCP/UDP transport protocol. Netstat–t Netstat–u
6, hostname can use the hostname command to change the host name. For example; hostname myhost
7, ARP can use the ARP command to configure and view the ARP cache. For example: (1) View the ARP cache. Arp
(2) Add a corresponding record for the IP address and MAC address. Arp–s 192.168.33.15 00:60:08:27:CE:B2
(3) Delete a corresponding cache record for an IP address and MAC address. arp–d192.168.33.15
Network configuration under the Ubuntu command line
Edit the/etc/network/interface file as follows
Add a reference first:
Auto Lo iface lo inet loopback auto eth0
If you are automatically getting IP, add a reference:
Iface eth0 inet DHCP
If you are configuring IP manually, add a reference:
Iface eth0 inet Static address xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx network xxx.xxx.xxx.xxx boardcast xxx.xxx.xxx.xxx g Ateway xxx.xxx.xxx.xxx