Centos7網路配置教程

2021-09-11 12:00:18 字數 3513 閱讀 3277

/etc/sysconfig/network # 包括主機基本網路資訊,用於系統啟動

/etc/sysconfig/network-script/ # 此目錄下是系統啟動最初始化網路的資訊

/etc/sysconfig/network-script/ifcfg-em1 # 網路配置資訊,每個人的配置名字不一樣通過命令檢視

/etc/xinetd.conf 定義了由超級程序xinetd啟動的網路服務

/etc/protocols # 設定了主機使用的協議以及各個協議的協議號

/etc/services # 設定了主機的不同埠的網路服務

複製**

在 centos 7 中 ifconfig 命令已經不靈了,換成了ip命令工具,輸入 ifconfig 會報如下錯誤:

ifconfig

-bash: ifconfig: command not found複製**

你可通過命令ls /usr/sbin/檢視這個目錄下 有沒有 ifconfig 工具,這個路徑一般是配置在環境變數上面,你通過檢視環境變數看一下放置系統管理程式的路徑 /usr/sbin 。

echo $path

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin複製**

如果沒有可以安裝乙個工具yum install net-toolsifconfig命令找回來。

ip [選項] 操作物件

ip link show                    # 顯示網路介面資訊

ip link set eth0 upi # 開啟網絡卡

ip link set eth0 down # 關閉網絡卡

ip link set eth0 promisc on # 開啟網絡卡的混合模式

ip link set eth0 promisc offi # 關閉網絡卡的混個模式

ip link set eth0 txqueuelen 1200 # 設定網絡卡佇列長度

ip link set eth0 mtu 1400 # 設定網絡卡最大傳輸單元

ip addr show # 顯示網絡卡ip資訊

ip addr add 192.168.0.1/24 dev eth0 # 設定eth0網絡卡ip位址192.168.0.1

ip addr del 192.168.0.1/24 dev eth0 # 刪除eth0網絡卡ip位址

ip route list # 檢視路由資訊

ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 設定192.168.4.0網段的閘道器為192.168.0.254,資料走eth0介面

ip route add default via 192.168.0.254 dev eth0 # 設定預設閘道器為192.168.0.254

ip route del 192.168.4.0/24 # 刪除192.168.4.0網段的閘道器

ip route del default # 刪除預設路由

複製**

通過 ip addr 命令 檢視ip。看到兩個配置,loem1,lo代表127.0.0.1,即localhost。em1這個是你的網絡卡,如果上面沒有 inet 字段後面跟著 ip 的話,你需要去配置檔案中修改配置。

預設配置檔案在這裡 /etc/sysconfig/network-scripts/ifcfg-em1 ,一般情況這個配置檔案是 ifcfg-《網絡卡名字》 加上你網絡卡名字,新的centos。執行下面命令編輯配置檔案。

vi /etc/sysconfig/network-scripts/ifcfg-em1複製**
主要更改這三項:bootproto=dhcponboot=yes,下面是我的配置檔案

# type:配置檔案介面型別。在/etc/sysconfig/network-scripts/目錄有多種網路配置檔案,有ethernet 、ipsec等型別,網路介面型別為ethernet。

type=ethernet

bootproto=dhcp # 自動獲取ip

# bootproto=none # 靜態配置,若該值為「dhcp」則為動態獲得,另外 static也是表示靜態ip位址

defroute=yes

peerdns=yes

peerroutes=yes

ipv4_failure_fatal=no

ipv6init=yes # 是否執行ipv6。yes:支援ipv6。no:不支援ipv6。

ipv6_autoconf=yes

ipv6_defroute=yes

ipv6_peerdns=yes

ipv6_peerroutes=yes

ipv6_failure_fatal=no

name=em1 # 網絡卡名稱

uuid=99-6217--a****** # uuid號,沒事不要動它,否則你會後悔的

device=em1 # 介面名稱

onboot=yes # 設定網路開機自動啟動

ipaddr0=192.168.21.128 # 設定ip位址

prefixo0=24 # 設定子網掩碼

gateway0=192.168.21.2 # 設定閘道器

dns1=8.8.8.8 # 設定主dns

dns2=8.8.4.4 # 設定備dns

複製**

ifup 《裝置名》    # 啟用網絡卡 

ifdown 《裝置名》 # 關閉網絡卡

ifup em1 # 啟用網絡卡 em1

複製**

修改配置檔案裡面 vi /etc/sysconfig/network-scripts/ifcfg-em1 的引數onboot=yes

service network start    # 啟動網路服務

service network stop # 停止網路服務

service network restart # 重啟網路服務

service network status # 檢視網路服務狀態

複製**

centos7網路配置: github.com/jaywcjlove/… 這裡持續更新

可以打賞了?

centOS7網路配置

開啟 etc sysconfig network scripts ifcfg eno xx 將bootprotot的值改為static 將onboot的值改為yes 尾部新增 ipaddr x.x.x.x gateway x.x.x.x netmask x.x.x.x 儲存退出 用以下命令重啟網路 ...

CentOS 7網路配置

剛安裝的centos7首先遇到的問題是 網路配置。如何讓新系統連線到網路?這裡配置的環境是基於vmware上安裝的centos,當然不在虛擬機器上的centos安裝後的網路配置方式也是一樣的。1 首先安裝的一般版本 除gnome kde圖形介面之外 是不帶圖形介面的,此時字元介面下ifconfig命...

Centos7 網路配置

配置網絡卡bootproto static onboot yes ipaddr 192.168.2.152 netmask 255.255.0.0 gateway 192.168.0.1 dns1 218.2.135.1 dns2 114.114.114.114 重啟networksystemctl...