Network Management of Linux
Linux network card configuration file: / etc/sysconfig/network-scripts/ifcf-xxx
DEVICE: this option is required for the device to which this profile is applied and needs to be configured correctly.
HWADDR: the MAC address of the corresponding device, which must match the mac address of the relevant network card. The default does not need to be modified.
BOOTPROTO: the address configuration protocol used to activate this device, and the common options that must be configured for dhcp, static, none, and bootp;.
ONBOOT: the option that must be configured to activate this device when the system boots.
TYPE: interface type; common Ethernet, options that Bridge; must configure
NM_CONTROLLED:NM is the abbreviation of NetworkManager; whether this Nic is controlled by NM; CentOS6 is recommended as "no"
UUID: unique identification of the device
IPADDR: indicates the IP address
NETMASK: subnet mask
GATEWAY: default gateway
DNS1: the first DNS server points to
DNS2: the second DNS server points to
USERCTL: whether the average user can control this device
PEERDNS: if the value of BOOTPROTO is "dhcp", whether to use the DNS of dhcp
The following is a reference network card configuration
[root@test-3 ~] # cat / etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0BOOTPROTO=dhcpHWADDR=00:0c:29:4e:f0:1aIPV6INIT=noNM_CONTROLLED=yesONBOOT=yesTYPE=EthernetUSERCTL=noPEERDNS=yes
Linux routing profile: / etc/sysconfig/network-scripts/route-xxx
1. Segment via Gateway
192.168.0.0/24 via 192.168.0.1
192.168.1.0/24 via 192.168.0.1
two。 Define a route every three lines
ADDRESS#=TARGET
NETMASK#=mask
GATEWAY#=GW
ADDRESS1=192.168.0.0
NETMASK1=255.255.255.0
GATEWAY1=192.168.0.1
Command line network management tool
1.ip
Ip [OPTIONS] OBJECT {COMMAND | help} # OBJECT can be {link | addr | route}
Ip link show displays all network hardware information
Ip link set dev interface up | down switch Nic
Ip addr displays all network hardware information
Ip addr add IP/MASK dev interface string network card configuration information
For example, ip addr add 192.168.0.0 Universe 24 dev eth2
Ip route show displays routing information
Ip route add IP/MASK via GW dev interface
For example, ip route add 192.168.0.0 dev eth0 24 via 192.168.0.1
For example, add a default gateway: ip route add default via 172.16.0.1 dev eth0
Ip route add IP/MASK dev IFACE string src SOURCE_IP
2.ifconfig
Ifconfig [interface]
Ifconfig-a displays all network hardware information
Ifconfig inferface up | down switch Nic
Ifconfig interface [aftype] options | address...
Ifconfig interface IP/MASK
For example, ifconfig eth0 10.0.0.1 Compact 24
Ifconfig interface IP netmask MASK
For example, ifconfig eth0 10.0.0.1 netmask 255.255.255.0
3.route
Route-n displays host routing information
Route add [- net |-host] target [netmask Nm] [gw Gw] [[dev] If] add routes
Destination: 192.168.1.3 Gateway: 172.16.0.1
Route add-host 192.168.1.3 gw 172.16.0.1 dev eth0
Destination: 192.168.0.0 Gateway: 172.16.0.1
Route add-net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 dev eth0
Route add-net 192.168.0.0 gw 24 gw 172.16.0.1 dev eth0
Default route, gateway: 172.16.0.1
Route add-net 0.0.0.0 netmask 0.0.0.0 gw 172.16.0.1
Route add default gw 172.16.0.1
Route del [- net |-host] target [gw Gw] [netmask Nm] [[dev] If] Delete a route
Destination: 192.168.1.3 Gateway: 172.16.0.1
Route del-host 192.168.1.3
Destination: 192.168.0.0 Gateway: 172.16.0.1
Route del-net 192.168.0.0 netmask 255.255.255.0
Nmcli [OPTIONS] OBJECT {COMMAND | help}
Device-show and manage network interfaces
Connection-start, stop, and manage network connections
Nmcli connection modify IFACE [+ | -] setting.property value
Setting.property:
Ipv4.addresses
Ipv4.gateway
Ipv4.dns1
Ipv4.method
Manual