---
title: "Centos DHCP开启，可以获得IP，但无法上网的问题"
author: "lasol"
date: "2011-09-08T23:38:52Z"
tags: []
slug: "centos-dhcp-ip"
draft: false
lastmod: "2011-09-08T23:38:52Z"
id: 1168949
url: "https://lasol.iteye.com/blog/1168949"
---

配置linux网络时候，可以ping通局域网，ping外网时提示： connect: network is unreachable  
这条命令就可以搞定：  
route add default gw 192.168.1.1  
后面那是你的网关。

现在 route 一下  
Kernel IP routing table  
Destination Gateway Genmask Flags Metric Ref Use Iface  
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0  
default my.router 0.0.0.0 UG 0 0 0 eth0

之前如果没有添加 的话， 只有上面的第一条。 第二条是新加进去的。  
如果还访问不了， 哪你的情况可能有点特殊哦。

这样重启以后 就不能 用了。  
修改  
编辑 /etc/network/interfaces  
添加 gateway 192.168.1.1 \[你自己的网关地址]