Ifconfig command for basic network configuration in Linux
1. The network configurations in Linux include: Network IP configuration, Gateway route configuration, host DNS configuration, and host name configuration. This article focuses on the network IP configuration. 2. Linux Network Address Configuration is divided into two methods: temporary network configuration: The network information configured using commands such as ifconfig will take effect immediately, but the network service and system restart will fail. Permanent Network Configuration: changes made by modifying the network configuration file in the system do not take effect immediately. You need to restart the network service or the system will take effect permanently. Iii. Network Interfaces and naming rules in Linux: (1) Network Interface: lo: local loopback interface erh [0-9]: Ethernet interface pppX: point-to-point connections (2), Ethernet NIC naming, and driver configuration file: REHL5:/etc/modprobe. conf alias ethX driver module REHL6:/etc/dev/rules. d/70-persistent-net.rules 4. ifconfig for network configuration (1) and ifconfig for viewing active Nic information, limited to active Nic Fg: first, check the information of the local Nic as follows -- ifconfig disables eth0 and then displays the information, as follows (2). Related sub-commands of ifconfig; ifconfig eth [0-9]: view the information of an Eni Fg: View eth0 Network Information ifconfig-a: View All Nic information, including active and inactive Fg: Disable eth0, then use ifconfig-a to view all Nic information ifconfig eth X IP/MASK: configure the IP address of a network adapter. Fg: Set the IP address of eth0 to 172.16.36.5/16 Ifconfig eth0 172.16.36.5/16 ifconfig ethx [up | down]: enable or disable the network information of a network adapter (3) or the above configuration. After the network service is restarted or the system is restarted, all configuration information will disappear. Command for restarting the network service in Linux: REHL5 network service command:/etc/init. d/network {start | stop | restart | status} REHL6 network service command:/etc/init. d/NetworkManger {start | stop | restart | status} v. route command: Used to view and modify the route information of the local machine. (1) and route: used to view the route information of the local machine. Route-n: displays the route information of the Local Machine in numbers. (2) Sub-command of route: route add: add host route add-host: add host route add-net: add network route add-net 0.0.0.0: add default route format: route add-net | host DEST gw NEXTHOP Fg: Access 192.168.0.0/24 network segment route del through 172.16.32.1: delete Route information Route del-host: route del-net: vi. IP (1) of network configuration commands and IP commands are a command in iproute2 package, which is more powerful than ifconfig and can configure IP and route information for the system. (2) ip link: configure network interface properties ip link show: view all network interface Property Information ip-s link show: view All Statistics ip link set ethX {up | down | arp {on | off}: set the operation attribute of the network interface (3), ip addr: configure the network address ip addr show: view Network Information ip addr add IP dev ethX: Configure ip address (NIC information configured by this command cannot be viewed by ifconfig, You need to view it by ip addr show) IP addr add ip dev ethx label ethX: x: configure the sub-Ip address and add the alias ip address addr show dev ethx to Prefix: view the information ip address addr flush eth1 to 10/8 on ethx: delete all IP addresses starting with 10 on eth1. (4) ip route: route information ip route change | replace: Modify route information ip route add to destination CIDR Block dev ethx via IP (Next Hop IP) Fg: add route information accessed through 172.16.36.3 in the network segment 10.0.0.0/8. 7. Nic alias settings commands and methods in the Linux system. (1) command configuration method: ifconfig and ip Ifconfig ethx: x IP/netmask ip addr add IP dev ethx label ethX: X (2) configuration file configuration method: Modify/etc/sysconfig/network-scripts/ifcfg-ethx: x DEVICE = ethx: x .... note: non-primary addresses cannot be obtained using the DHCP service. 8. IP network configuration file (1) and network configuration file location:/etc/sysconfig/network interface configuration file location: /etc/sysconfig/network-scripts/ifcfg-INTERFACE_NAME (2), ifcfg-ethx configuration format: DEVICE =: the name of the associated DEVICE, to save one to BOOTPROTO = {static | none | dhcp | bootp} with the last half of the file name "INTERFACE_NAME": Boot Protocol, use static address, use static or none, dhcp indicates that the IP address is obtained by the dhcp server. IPADDR =: IP address NETMASK =: Subnet Mask GAYEWAY =: Set gateway ONBOOT =; Whether to automatically activate this network interface HWADDR =: hardware address, must be consistent with the address in the hardware, can save. USERCTL = {yes | no}: whether to allow normal users to control this interface PEERDNS = {yes | no }: whether or not to accept the DNS address specified by the dhcp server when BOOTPROTO is dhcp does not take effect immediately, but the network service or host restart will take effect. Permanent active Fg: configure the local IP address to 172.16.36.1/18. 9. route configuration file: (1). Configuration File Location:/etc/sysconfig/network-scripts/route-ethx: indicates the network adapter route (2). Configuration format: Add format 1: DEST (destination) via NEXTTOP (Next Hop) add Format 2: ADDRESS0 = network address (Destination Address) NETMASK0 = Subnet Mask (destination network) GATEWAY0 = Gateway (gateway through that Nic) ADDRESS1 = NETMASK1 = GATEWAY1 = the above settings do not take effect immediately, but the restart of the network service or host will take effect. 10. DNS configuration file: (1). Location of the configuration file:/etc/resolv. conf (2) configuration format: nameserver DNS_IP1 nameserver DNS_IP2 specifies local resolution: add the target host IP host name host alias fg under/etc/hosts: 172.16.36.1 www.chris.com wwwDNS resolution process -->/etc/hosts --> DNS 11, host name configuration file: (1), configuration file location:/etc/sysconfig/network (2), configuration format: HOSTNAME = Name NETWORKING = {yes | no}: whether to enable the network function NETWORKING