CentOS 網路介面配置檔案配置示例及詳解

2021-10-10 10:22:28 字數 1673 閱讀 6931

在 centos 中,網路配置檔案一般為 /etc/sysconfig/network-scripts/ifcfg-裝置名稱,比如 ifcfg-eth0、ifcfg-ens32、ifcfg-enp8s0 等。

配置檔案示例(假設網絡卡裝置為 ens32):

# 安裝後預設配置,動態獲取 ip 位址

type=ethernet # 網路型別。ethernet 、ipsec 等型別,預設型別為 ethernet (乙太網)

proxy-method=none

browser_only=no

hwaddr=00:0c:29:13:5d:74 # 網絡卡 mac 位址

bootproto=dhcp # 網絡卡獲得 ip 位址的方式

defroute=yes # 是否使用預設路由

ipv4_failure_fatal=no # 是否開啟 ipv4 致命錯誤檢測

ipv6init=yes # ipv6 是否自動初始化

ipv6_autoconf=yes # ipv6 是否自動配置

ipv6_defroute=yes # ipv6 是否使用預設路由

ipv6_failure_fatal=no # 是否開啟 ipv6 致命錯誤檢測

ipv6_addr_gen_mode=stable-privacy

device=eth32 # 網路介面物理裝置名稱

name=ens32

uuid=b7f184cb-8c09-40e7-8279-c62a3318c8f6 # 網路介面的唯一裝置 id

onboot=yes # 系統啟動時是否啟用網路介面

# 設定靜態 ip 位址(bootproto=)

ipaddr=192.168.1.128 # 設定靜態 ip 位址

netmask=255.255.255.0 # 設定網路掩碼,可選配置方式: prefix=24

gateway=192.168.1.1 # 設定閘道器位址

nm_controlled=yes # 設定是否由 network manager 管理此網路介面

peerdns=yes # 是否指定 dns ,當 peerdns 為 yes 時會覆蓋 /etc/resolv.conf 中設定的 dns

dns1=8.8.8.8 # dns 位址。當 peerdns 為 yes 時會覆蓋 /etc/resolv.conf 中設定的 dns

dns2=114.114.114.114

userctl=no # 非 root 使用者是否可以控制此網路介面

其它配置引數說明

bootproto:引導時使用的協議

broadcast:廣播位址

hwaddr/macaddr:mac 位址。只需設定其中乙個,同時設定時不能相互衝突

ipv6_privacy: 是否支援 rfc 3041

注:詳盡全面的配置引數說明請查閱 nm-settings-ifcfg-rh(5) man page。

配置生效

重啟網路服務 ,執行 命令。

CentOS網路介面配置檔案ifcfg eth詳解

centos網路介面配置檔案ifcfg eth詳解 檔案 etc sysconfig network scripts ifcfg eth0在 etc sysconfig network script在這個目錄下面,存放的是網路介面 網絡卡 的指令碼檔案 控制檔案 ifcfg eth0是預設的第乙個網...

CentOS網路介面配置檔案ifcfg eth詳解

centos網路介面配置檔案ifcfg eth詳解 檔案 etc sysconfig network scripts ifcfg eth0在 etc sysconfig network script在這個目錄下面,存放的是網路介面 網絡卡 的指令碼檔案 控制檔案 ifcfg eth0是預設的第乙個網...

CentOS網路介面配置檔案ifcfg eth詳解

centos網路介面配置檔案ifcfg eth詳解 檔案 etc sysconfig network scripts ifcfg eth0在 etc sysconfig network script在這個目錄下面,存放的是網路介面 網絡卡 的指令碼檔案 控制檔案 ifcfg eth0是預設的第乙個網...