Basic Linux Network Configuration
1. TCP/IP network configuration file
/Etc/sysconfig/network-scripts/ifcfg-eth0
/Etc/sysconfig/network
/Etc/host. conf
/Etc/hosts
/Etc/resolv. conf
/Etc/services
(1)/etc/sysconfig/network-scripts/ifcfg-eth0
Network Interface Startup Script
Content instance:
DEVICE = eth0
ONBOOT = yes
BOOTPROTO = static
IPADDR = 192.168.1.10
NETMASK = 255.255.255.0
GATEWAY = 192.168.1.1
NETWORK = 192.168.1.0
BROADCAST = 192.168.1.255
(2)/etc/sysconfig/network
Basic Network Information Configuration
Content instance:
NETWORKING = yes
HOSTNAME = linux.jnrp.cn
GATEWAY = 192.168.1.1
(3)/etc/hosts
The/etc/hosts file is the local host name resolution database of the system.
Content instance:
# Do not remove the following line, or various programs
# That require network functionality will fail.
127.0.0.1 localhost. localdomain localhost
192.168.1.2 CentOS5
(4)/etc/host. conf
The/etc/host. conf file is used to specify how to resolve the host name. Available options include:
Order: Set the available methods and sequence for host name resolution. Available methods include hosts (using the/etc/hosts file for resolution) and bind (using DNS Server Resolution), nis (using Network Information Service NIS resolution)
Multi: sets whether to return multiple IP addresses of the host from the/etc/hosts file. The value is on/off.
(5)/etc/resolv. conf
The/etc/resolv. conf file is the client configuration file of the DNS domain name service.
Content instance:
Nameserver 218.30.19.40
Nameserver61.134.1.4
Search jnrp.cn
Domain jnrp.cn
(6)/etc/services
Set the default TCP or UDP port used by the Network Service
File Content instance:
# Each linedescribes one service, and is of the form:
#
# Service-name port/protocol [aliases...] [# comment]
Tcpmux 1/tcp # TCP port servicemultiplexer
Tcpmux 1/udp # TCP port servicemultiplexer
Ipve 5/tcp # Remote Job Entry
Rje 5/udp # Remote Job Entry
Echo 7/tcp
Echo 7/udp
Discard 9/tcp sink null
Discard 9/udp sink null
Listen at 11/tcp users
Protocol at 11/udp users
2. Use the command line tool to configure the network
Basic network configuration command:
Ifconfig
Ifup
Ifdown
Hostname
(1) ifconfig command
The ifconfig command is used to view and Configure TCP/IP networks.
Command instance:
# Ifconfig eth0
Eth0 Link encap: Ethernet HWaddr 00: 0C: 29: FB: E4: 89
Inet addr: 192.168. 1.3 Bcast: 192.168. 1.255 Mask: 255.255.255.0
Inet6 addr: fe80: 20c: 29ff: fefb: e489/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 36 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 139 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 4321 (4.2 KiB) TXbytes: 13153 (12.8 KiB)
Interrupt: 10 Base address: 0x1400
# Ifconfig eth0 192.168.1.3 netmask 255.255.255.0
(2) route command
The route command is used to set the route information of the Linux system.
View route information:
Route-n
Add a static route entry
Route add-net netaddr netmask gw ipaddr dev
Set the Default Gateway
Route add default gw ipaddr
Delete A route entry
Route del-net netaddr netmask gw ipaddr dev
Ping Command to test network connection through ICMP protocol
The traceroute command can trace the path to a specific destination.
The netstat command is used to view various network-related status information, including the network connection status, interface statistics, and route table and port monitoring information.
(3) ping command
The basic usage of the ping command is:
Destination Address of the ping Option
Common options include:
-C: specify the number of ICMP messages sent by the ping command. If this parameter is not specified, the ICMP messages will be sent continuously until you press ctrl + c to stop the command.
-I: Specifies the interval between the ping command and each ICMP message. The default value is 1 second. For security reasons, only super users can set this value to less than 0.2 seconds.
-S: sets the size of each ICMP message. The default value is 64 bytes and the maximum value is 65507.
-T: Set ttl (Time to Live)
(4) traceroute command
(5) netstat command
Common netstat Commands include:
-A: displays all listening and non-listening sockets.
-I: displays statistics of interfaces.
-N: the IP address and port are displayed in numbers instead of names.
-P: displays the PID and program name of the process using the port.
-R: displays the kernel route table.
-S: displays statistics for each protocol