virtual box 安裝了centos 7最小模式後馬上用ifconfig命令檢視網路情況,發現該命令不存在。
網上搜尋資料才發現 centos 7已經用ip命令代替ifconfig命令了。[root@centos1 ~]# ifconfig
-bash: ifconfig: command not found
可以使用下面命令檢視網路情況:
id addr
下面列出ip命令常用引數。
需要新增靜態ip,請將新新增的網絡卡2設定虛擬機器橋接模式:設定->網路->網絡卡2: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 # 刪除預設路由
重啟虛擬機器後,修改配置檔案:
cd /etc/sysconfig/network-scripts/
發現網絡卡ip資訊的配置檔名也由以前的ifcfg-eth0變成了ifcfg-enp2s0 等,我這裡是ifcfg-enp2s8.
virtual box預設的網絡卡1的連線方式是網路位址轉換(nat),只需要將ifcfg-enp2s8配置裡改onboot改為yes,然後service network restart就有網路了。
將onboot改為yes,bootproto注釋掉。type=ethernet
bootproto=dhcp
defroute=yes
peerdns=yes
peerroutes=yes
ipv4_failure_fatal=no
ipv6init=yes
ipv6_autoconf=yes
ipv6_defroute=yes
ipv6_peerdns=yes
ipv6_peerroutes=yes
ipv6_failure_fatal=no
name=enp2s0
uuid=5b0a7d76-1602-4e19-aee6-29f57618ca01
onboot=no
如果需要新增靜態ip,則新增當前網路資訊:
這裡因為我電腦正常上網的ip是192.168.1.101,所以我寫成了192.168.1.107。ipaddr0=192.168.1.107
gateway0=192.16.1.1
重啟網路:
service network restart
試試有沒有網路:
ping qq.com
能返回資訊,說明正常了。
有網就好辦了,你想繼續使用ifconfig,沒問題,安裝吧:
yum install net-tools
還可以安裝其他應用:
yum install vim
yum install wget
yum install lrzsz
yum install gcc
yum install telnet*
# 安裝ping命令
yum install -y iputils
wget -o netcat-0.7.1.tar.gz
參考:
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...