Centos 7 學習之靜態IP設定

來源:互聯網
上載者:User

標籤:

原文連結:http://blog.csdn.net/johnnycode/article/details/40624403

本學習主要針對 Centos 7.0.1406 版本進行學習整理!

如果你使用 VirtualBox 配置 Centos 那麼請參考我的這篇文章 Centos 7 學習之靜態IP設定(續)

1、編輯 ifcfg-eth0 檔案,vim 迷你安裝時沒有被安裝,需要自行安裝不描述。

[plain] view plain copy  
  1. # vim /etc/sysconfig/network-scripts/ifcfg-eth0  

2、修改如下內容

[plain] view plain copy  
  1. BOOTPROTO="static" #dhcp改為static   
  2. ONBOOT="yes" #開機啟用本配置  
  3. IPADDR=192.168.7.106 #靜態IP  
  4. GATEWAY=192.168.7.1 #預設閘道  
  5. NETMASK=255.255.255.0 #子網路遮罩  
  6. DNS1=192.168.7.1 #DNS 配置  

3、修改後效果

[plain] view plain copy  
  1. # ]# cat /etc/sysconfig/network-scripts/ifcfg-eth0  
  2. HWADDR="00:15:5D:07:F1:02"  
  3. TYPE="Ethernet"  
  4. BOOTPROTO="static" #dhcp改為static   
  5. DEFROUTE="yes"  
  6. PEERDNS="yes"  
  7. PEERROUTES="yes"  
  8. IPV4_FAILURE_FATAL="no"  
  9. IPV6INIT="yes"  
  10. IPV6_AUTOCONF="yes"  
  11. IPV6_DEFROUTE="yes"  
  12. IPV6_PEERDNS="yes"  
  13. IPV6_PEERROUTES="yes"  
  14. IPV6_FAILURE_FATAL="no"  
  15. NAME="eth0"  
  16. UUID="bb3a302d-dc46-461a-881e-d46cafd0eb71"  
  17. ONBOOT="yes" #開機啟用本配置  
  18. IPADDR=192.168.7.106 #靜態IP  
  19. GATEWAY=192.168.7.1 #預設閘道  
  20. NETMASK=255.255.255.0 #子網路遮罩  
  21. DNS1=192.168.7.1 #DNS 配置  

4、重啟下網路服務

 

[plain] view plain copy  
  1. # service network restart  

 

5、查看改動後的效果,Centois 7 不再使用 ifconfig 而是用 ip 命令查看網路資訊。

 

[plain] view plain copy  
  1. # ip addr  
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN   
  3.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
  4.     inet 127.0.0.1/8 scope host lo  
  5.        valid_lft forever preferred_lft forever  
  6.     inet6 ::1/128 scope host   
  7.        valid_lft forever preferred_lft forever  
  8. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000  
  9.     link/ether 00:15:5d:07:f1:02 brd ff:ff:ff:ff:ff:ff  
  10.     inet 192.168.7.106/24 brd 192.168.7.255 scope global eth0  
  11.        valid_lft forever preferred_lft forever  
  12.     inet6 fe80::215:5dff:fe07:f102/64 scope link   
  13.        valid_lft forever preferred_lft forever  

 

 

在安裝時 設定了靜態ip 但是 使用ifconfig命令時  只有 127.0.0.1的ip地址 

這時候查看/etc/sysconfig/network-scripts  目錄下是否存在ifcfg-eth0 檔案如果不存在 查看是否存在ifcfg-開頭的檔案 

我的系統存在ifcfg-eno16777736這樣一個檔案

more ifcfg-eno16777736

[[email protected] network-scripts]$ more ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=7170eda3-8183-41fc-b0b8-ee924d05ddc2
ONBOOT=no
IPADDR0=192.168.0.88
PREFIX0=24
HWADDR=00:0C:29:61:34:7D
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

剛好為我在安裝系統時添加的ip資訊

此時 使用命令 cp  ifcfg-eno16777736 ifcfg-eth0  建立 ifcfg-eth0檔案 同時將內容中的ONBOOT=no 改為 ONBOOT=yes

執行命令 service network restart 

執行 ifconfig 出現正確網路資訊

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.88  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe61:347d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:61:34:7d  txqueuelen 1000  (Ethernet)
        RX packets 102  bytes 10385 (10.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 128  bytes 13681 (13.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 818  bytes 71132 (69.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 818  bytes 71132 (69.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

如果安裝環境為 vm虛擬機器的host-only 下 想在虛擬機器中上網  

找到win環境下的網卡vmnet1  通過屬性 tcp/ip協議查看 他的ip地址 

假設這裡為 192.168.0.12 而虛擬機器中設定的ip是IPADDR0=192.168.0.88 需要在 ifcfg-eth0添加網關為 當前win的vmnet1的ip地址

即添加 GETEWAY=192.168.0.12 

在win上必須有一個能上網的網卡 比如我的筆記本為 無線網卡 右鍵屬性 進階 允許其他網路通過此電腦的internet來串連勾上 下拉框 選上 vmnet的網卡

確定 如果彈出確認 選否即可

通過ipconfig -all命令 查看 無線網卡的 dns伺服器 比如我的 如下

Ethernet adapter 無線網路串連:
       Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : Broadcom 802.11n 網路
        Physical Address. . . . . . . . . : 08-3E-8E-4A-38-AB
        Dhcp Enabled. . . . . . . . . . . : Yes
        Autoconfiguration Enabled . . . . : Yes
        IP Address. . . . . . . . . . . . : 192.168.1.100
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.1.1
        DHCP Server . . . . . . . . . . . : 192.168.1.1
        DNS Servers . . . . . . . . . . . : 211.162.66.66
                                            211.162.77.77

在  ifcfg-eth0添加DNS伺服器 我這裡有兩個 

添加兩行 

DNS1=211.162.66.66

DNS2=211.162.77.77

此時在虛擬機器的 linux 重啟 service network restart

ping www.baidu.com 成功

http://blog.csdn.net/johnnycode/article/details/40624403

Centos 7 學習之靜態IP設定

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.