在Linux操作系统中一切皆文件,IP地址的配置文件是/etc/sysconfig/network-scripts/ifcfg-eth0
,如果有多个网卡名称可以是ifcfg-eth1、ifcfg-eth2等等,也可能是其它名称ifcfg-*
在系统开机的时候,会加载该配置文件,进行IP地址等网络信息的配置
/etc/sysconfig/network-scripts/ifcfg-eth0 #网卡、网关、DNS等
/etc/resolv.conf #DNS配置
/etc/hosts #域名和IP的映射
/etc/sysconfig/network #网关配置等
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 #网卡广播地址
管理全部网络接口
=========================
[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接口
ifconfig #查看网卡信息
ip addr show #查看网卡信息
ip a #同上,简写形式
netstat -r #查看路由表
route #查看路由表
[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
[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
# 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
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/