標籤:des style blog http io ar color os sp
1,設定網卡,ip
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #描述網卡對應的裝置別名,例如ifcfg-eth0的檔案中它為eth0 BOOTPROTO=static #設定網卡獲得ip地址的方式,可能的選項為static,dhcp或bootp,分別對應靜態指定的 ip地址,通過dhcp協議獲得的ip地址,通過bootp協議獲得的ip地址 BROADCAST=192.168.0.255 #對應的子網廣播位址 HWADDR=00:07:E9:05:E8:B4 #對應的網卡物理地址 IPADDR=192.168.0.2 #如果設定網卡獲得 ip地址的方式為靜態指定,此欄位就指定了網卡對應的ip地址 IPV6INIT=no IPV6_AUTOCONF=no NETMASK=255.255.255.0 #網卡對應的網路遮罩 NETWORK=192.168.0.0 #網卡對應的網路地址 ONBOOT=yes #系統啟動時是否設定此網路介面,設定為yes時,系統啟動時啟用此裝置
重啟網卡
service network restart
測試網路:
ping www.baidu.com
很多時候用百度測試網路連通性,^_^
如果可以ping通,那當就ok了。如果ping不通
[[email protected] ~]# ping www.baidu.comping: unknown host www.baidu.com
設定網關路由
route add default gw 網關ip
感覺default這一行對應的gateway必須是localhost才管用呢。第一次設定完,是ip
[[email protected] ~]# netstat -rKernel IP routing tableDestination Gateway Genmask Flags MSS Window irtt Iface172.16.0.0 * 255.255.255.0 U 0 0 0 eth0link-local * 255.255.0.0 U 0 0 0 eth0default 172.16.0.1 0.0.0.0 UG 0 0 0 eth0[[email protected] ~]# ping www.baidu.comping: unknown host www.baidu.com
然後設定了 /etc/resolv.conf 檔案
設定nameserver
nameserver 202.106.0.20nameserver 202.106.196.115
重啟網卡
再次查看
[[email protected] ~]# netstat -rKernel IP routing tableDestination Gateway Genmask Flags MSS Window irtt Iface172.16.0.0 * 255.255.255.0 U 0 0 0 eth0link-local * 255.255.0.0 U 0 0 0 eth0default localhost 0.0.0.0 UG 0 0 0 eth0
樂意串連上外網了
[[email protected] ~]# ping www.baidu.comPING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.64 bytes from 61.135.169.125: icmp_seq=1 ttl=56 time=1.40 ms64 bytes from 61.135.169.125: icmp_seq=2 ttl=56 time=1.57 ms
原理還不是很清楚。先mark一下。
linux設定好IP後,可以訪問內網,不能訪問外網