CentOS7 network card and DNS configuration

Key words

  • /etc/sysconfig/network-scripts/ifcfg-eth0
  • Network card
  • Network Interface
  • DNS
  • Network card configuration file

How does Linux load IP address information?

In the Linux operating system, everything is a file. The configuration file of the IP address is /etc/sysconfig/network-scripts/ifcfg-eth0. If there are multiple network card names, it can be ifcfg-eth1, ifcfg-eth2, etc., or other names.ifcfg-*

When the system is turned on, the configuration file will be loaded to configure the network information such as the IP address

Redhat series network related configuration files

/etc/sysconfig/network-scripts/ifcfg-eth0 #网卡、网关、DNS等
/etc/resolv.conf          #DNS配置
/etc/hosts                #域名和IP的映射
/etc/sysconfig/network    #网关配置等

Common configuration explanation

TYPE=Ethernet             #网卡类型
DEVICE=eth0               #网卡接口名称
ONBOOT=yes                #系统启动时是否自动加载,删除此项即关闭开机网卡自启动
BOOTPROTO=none            #启用地址协议,dhcp动态IP分配;none不使用启动协议,用在静态IP分配时
IPADDR=192.168.1.11       #IP地址
NETMASK=255.255.255.0     #子网掩码
GATEWAY=192.168.1.1       #网关地址
DNS1=10.203.104.41        #网卡DNS地址1
DNS2=8.8.8.8              #网卡DNS地址2
HWADDR=00:0C:29:13:5D:74  #网卡设备MAC地址
BROADCAST=192.168.1.255   #网卡广播地址

NIC start and stop

管理全部网络接口
=========================
[root@192_168_31_106 ~]# /etc/init.d/network
Usage: /etc/init.d/network {start|stop|status|restart|force-reload}
生产环境操作网卡要额外注意,一旦配置错误,可能导致SSH连接掉线


管理单个网络接口
=========================
ifdown eth0 #关闭eth0接口
ifup eth0   #打开eth0接口

Common network management commands

ifconfig      #查看网卡信息
ip addr show  #查看网卡信息
ip a          #同上,简写形式
netstat -r    #查看路由表
route         #查看路由表

Production environment configuration example 1 (QEMU virtual machine)

[root@192_168_31_106 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eth0"
UUID="8feec78a-efc7-481c-afbc-68bad55d0a74"
DEVICE="eth0"
ONBOOT="yes"
IPADDR=192.168.31.106
NETMASK=255.255.255.0
GATEWAY=192.168.31.1
DNS1=192.168.31.1
DNS2=8.8.8.8

Production environment configuration example 2 (Alibaba Cloud)

[root@192_168_1_237 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
# If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
# For more information, please refer to: https://help.aliyun.com/document_detail/57803.html
#
BOOTPROTO=dhcp
DEVICE=eth0
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no

Production environment configuration example 3 (physical machine)

# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth0
ONBOOT=yes
HWADDR=78:8B:CB:20:2B:36
TYPE=Ethernet
BOOTPROTO=none
IPADDR=10.10.188.21
NETMASK=255.255.255.0

Reference

https://blog.csdn.net/qq847270942/article/details/48276323
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s1-networkscripts-interfaces
https://www.thegeekdiary.com/understanding-the-network-interface-configuration-file-etc-sysconfig-network-scripts-ifcfg-eth/

Guess you like

Origin blog.csdn.net/xys2015/article/details/114268090