解決centos ping不通外網

來源:互聯網
上載者:User

標籤:

一。ip

二。網關

三。dns

一就不說了,設定好本地ip和掩碼就行了,二網關   添加預設閘道,命令:route add defaule gw 192.168.1.1 這是 你用route命令查看最下面會有一條預設路由,走192.168.1.1網關,當然這個網關是根據你本地的網段決定的,三 就是dns了,dns也需要到設定檔修改,#vi etc/resolv.conf 檔案,我的檔案預設是空白的。添加一條dns記錄就可以了,比如我在河南,我添加:nameserver 222.85.85.85 然後儲存退出,OK

ping通外網了。

順便記一下幾個命令:

刪除預設路由 :

route 命令

設定和查看路由表都可以用 route 命令,設定核心路由表的命令格式是:

# route  [add|del] [-net|-host] target [netmask Nm] [gw Gw] [[dev] If]

其中:

  • add : 添加一條路由規則
  • del : 刪除一條路由規則
  • -net : 目的地址是一個網路
  • -host : 目的地址是一個主機
  • target : 目的網路或主機
  • netmask : 目的地址的網路遮罩
  • gw : 路由資料包通過的網關
  • dev : 為路由指定的網路介面
route 命令使用舉例

添加到主機的路由

# route add -host 192.168.1.2 dev eth0:0
# route add -host 10.20.30.148 gw 10.20.30.40

添加到網路的路由

# route add -net 10.20.30.40 netmask 255.255.255.248 eth0
# route add -net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41
# route add -net 192.168.1.0/24 eth1

添加預設路由

# route add default gw 192.168.1.1

刪除路由

# route del -host 192.168.1.2 dev eth0:0
# route del -host 10.20.30.148 gw 10.20.30.40
# route del -net 10.20.30.40 netmask 255.255.255.248 eth0
# route del -net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41
# route del -net 192.168.1.0/24 eth1
# route del default gw 192.168.1.1

解決centos ping不通外網

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.