Linux system-basic network configuration and troubleshooting
In linux, there are three types of network configuration: one is to directly implement the configuration file using command lines on the terminal, and the other is to modify the configuration file, another method is setup text interface settings.
The difference is that after the configuration file is modified, it will take effect permanently without being changed (the service must be restarted, Which is set in the setup text mode ), however, the command takes effect immediately but becomes invalid after restart.
1. modify the configuration file
In Linux, the NIC must be configured first, whether connected to the Internet or lan. The default path of the NIC configuration file is in the/etc/sysconfig/network-scripts directory, by default, there are two NICs, one physical NIC (eth0) and one loopback NIC (lo). Their configuration files are ifcfg-eth0 and ifcfg-lo, respectively. if you add a new Nic, so his configuration file is the ifcfg-eth1
[Root @ localhost ~] # Vi/etc/sysconfig/network-scripts/ifcfg-eth0 # Use the vi editor to open the NIC configuration file
TYPE = Ethernet # Nic TYPE, which is not modified
DEVICE = eth0 # Nic interface name, which is generally not modified. If it is newly added, note that you should change it to the corresponding
ONBOOT = yes # whether the system is automatically loaded at startup
BOOTPROTO = static # enable address protocol -- static: static protocol -- bootp protocol -- default value of dhcp protocol is none. If static IP address is set, do not modify it. If it is obtained from the dhcp server, change to dhcp.
IPADDR = 192.168.1.11 # Nic IP Address
NETMASK = 255.255.255.0 # subnet mask of the Network Adapter
GATEWAY = 192.168.1.1 # Nic GATEWAY address
DNS1 = 8.8.8.8 # Nic DNS address. If multiple DNS addresses exist, DNS2 = ......
HWADDR = 00: 0C: 29: 13: 5D: 74 # Nic device MAC address
BROADCAST = 192.168.1.255 # Nic BROADCAST address
After the configuration file is modified, restart the service or re-load the configuration to make it take effect.
[Root @ localhost ~] #/Etc/init. d/network reload # reload Configuration
[Root @ localhost ~] #/Etc/init. d/network restart # restart the service
You can also use service network restart/reload
Ii. Temporary modification through command line
[Root @ localhost ~] # Ifconfig eth0 192.168.1.1 netmask 255.255.255.0 # directly use commands to modify the NIC
Or
[Root @ localhost ~] # Ifconfig eth0 10.1.1.10/24
[Root @ localhost ~] # Ifconfig eth0: 0 127.0.0.1 # Add a virtual address for the network adapter eth0. Both ip addresses can be used
Iii. setup text mode configuration
[Root @ localhost ~] # Setup
4. Configure routes
[Root @ localhost ~] # Route-net 192.168.3.0/24 gw 192.168.2.1 # Add a static route-net followed by the destination CIDR Block gw and the next hop address
[Root @ localhost ~] # Route del-net 192.168.3.0/24 # delete a static route
[Root @ localhost ~] # Route add/del default gw 192.168.1.1 # add/delete a default route
V. Network startup and Shutdown
[Root @ localhost ~] # Ifdown eth0 # disable the network
[Root @ localhost ~] # Ifup eth0 # Start the network
Or
[Root @ localhost ~] # Ifconfig eth0 up # Start the network
[Root @ localhost ~] # Ifconfig eth0 down # disable the network
6. Various query commands
[Root @ localhost ~] # Service network status # Nic status query
[Root @ localhost ~] # Ifconfig # list all interfaces by default
[Root @ localhost ~] # Ifconfig eth0 # list eth0 Nic Information
[Root @ localhost ~] # Netstat-r # view route information
[Root @ localhost ~] # Route (-n) # view route information. Adding-n is displayed as a number.
[Root @ localhost ~] # Traceroute 192.168.1.1 # tracking Routing
Conclusion: When we ping an IP address, if the firewall is not blocked and the peer network is normal, we should first check whether our network card is correctly configured (ignore physical layer issues, such as network cable failure --#)
1. Enable Nic
2. Whether the NIC parameters are correctly configured (your ip address, mask, gateway, DNS, etc)
3. Is there a route to the other party, and is the route configured correctly?
4. Whether the network service is enabled
In addition, refer to the error prompt or system log for error troubleshooting.