方法1
手動(dòng)配置Centos7系統(tǒng)里的網(wǎng)絡(luò)配置
cd /etc/sysconfig/network-scripts
ls #找到當(dāng)前網(wǎng)絡(luò)配置文件為ifcfg-ens33
sudo vim ifcfg-ens33
#修改如下網(wǎng)絡(luò)配置
BOOTPROTO=static #以靜態(tài)方式獲取IP
IPADDR=192.168.1.100 #IP地址為192.168.1.100(192.168.1.0網(wǎng)段內(nèi))
NETMASK=255.255.255.0
GATEWAY=192.168.1.1 #網(wǎng)關(guān)需要與IP在一個(gè)網(wǎng)段內(nèi)
DNS1=192.168.1.1
ONBOOT=yes #開(kāi)機(jī)啟動(dòng)網(wǎng)卡
:wq #保存退出
方法2
Ip [選項(xiàng)] 操作對(duì)象{link|addr|route…}
# ip link show # 顯示網(wǎng)絡(luò)接口信息
# ip link set eth0 upi # 開(kāi)啟網(wǎng)卡
# ip link set eth0 down # 關(guān)閉網(wǎng)卡
# ip link set eth0 promisc on # 開(kāi)啟網(wǎng)卡的混合模式
# ip link set eth0 promisc offi # 關(guān)閉網(wǎng)卡的混個(gè)模式
# ip link set eth0 txqueuelen 1200 # 設(shè)置網(wǎng)卡隊(duì)列長(zhǎng)度
# ip link set eth0 mtu 1400 # 設(shè)置網(wǎng)卡最大傳輸單元
# ip addr show # 顯示網(wǎng)卡IP信息
# ip addr add 192.168.0.1/24 dev eth0 # 設(shè)置eth0網(wǎng)卡IP地址192.168.0.1
# ip addr del 192.168.0.1/24 dev eth0 # 刪除eth0網(wǎng)卡IP地址
# ip route list # 查看路由信息
# ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 設(shè)置192.168.4.0網(wǎng)段的網(wǎng)關(guān)為192.168.0.254,數(shù)據(jù)走eth0接口
# ip route add default via 192.168.0.254 dev eth0 # 設(shè)置默認(rèn)網(wǎng)關(guān)為192.168.0.254
# ip route del 192.168.4.0/24 # 刪除192.168.4.0網(wǎng)段的網(wǎng)關(guān)
# ip route del default # 刪除默認(rèn)路由
重啟網(wǎng)卡檢查配置
sudo systemctl restart network #重啟網(wǎng)卡
sudo systemctl enable network #開(kāi)機(jī)啟動(dòng)網(wǎng)卡
ifconfig #查看網(wǎng)卡信息
ping www.baidu.com #能PING通就是聯(lián)網(wǎng)成功

版權(quán)聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶(hù)自發(fā)貢獻(xiàn),該文觀點(diǎn)僅代表作者本人。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如發(fā)現(xiàn)本站有涉嫌抄襲侵權(quán)/違法違規(guī)的內(nèi)容, 請(qǐng)發(fā)送郵件至2705686032@qq.com 舉報(bào),一經(jīng)查實(shí),本站將立刻刪除。原文轉(zhuǎn)載: 原文出處: