Linux set up IP, you can access the intranet, no access to the external network

Source: Internet
Author: User

1, set the network card, IP

Device=eth0 #描述网卡对应的设备别名, for example, in Ifcfg-eth0 file it is eth0   bootproto=static #设置网卡获得ip地址的方式, the possible options are static,dhcp or BOOTP, Corresponding to statically specified IP addresses, IP addresses obtained through the DHCP protocol, IP addresses obtained through the BOOTP protocol   broadcast=192.168.0.255 #对应的子网广播地址   Hwaddr=00:07:e9:05:e8 : B4 #对应的网卡物理地址   ipaddr=192.168.0.2 #如果设置网卡获得 IP address is specified statically, this field specifies the IP address of the NIC   ipv6init=no   ipv6_autoconf= No   netmask=255.255.255.0 #网卡对应的网络掩码   network=192.168.0.0 #网卡对应的网络地址   onboot=yes #系统启动时是否设置此网络接口, when set to Yes , this device is activated at system startup

Restart the NIC
Service Network restart  

Test network:

Ping www.baidu.com

Many times use Baidu to test network connectivity, ^_^

If you can ping the pass, then it is OK. If the ping does not pass

[Email protected] ~]# Ping Www.baidu.comping:unknown host www.baidu.com

Set up Gateway Routing

Route add default  GW  Gateway IP



It feels like the default gateway must be localhost. After the first setup, it is the IP
[Email protected] ~]# netstat-rkernel IP Routing tabledestination Gateway genmask Flags MSS Window irtt Iface172.16.0.0*255.255.255.0U0 0          0Eth0link-local *255.255.0.0U0 0          0eth0default         172.16.0.1      0.0.0.0Ug0 0          0Eth0[[email protected]~]# Ping Www.baidu.comping:unknown host www.baidu.com

Then set up the/etc/resolv.conf file

Set nameserver

202.106. 0.20  202.106. 196.115

Restart the NIC

Check Again

[Email protected] ~]# netstat-rkernel IP Routing tabledestination Gateway genmask Flags MSS Window irtt Iface172.16.0.0*255.255.255.0U0 0          0Eth0link-local *255.255.0.0U0 0          0eth0defaultlocalhost0.0.0.0Ug0 0          0Eth0

Happy to connect to the Sisu network.

[[Email protected] ~]# Ping Www.baidu.comPING www.a.shifen.com (61.135.169.125) About( -) bytes of data. -bytes from 61.135.169.125: icmp_seq=1Ttl= AboutTime=1.40Ms -bytes from 61.135.169.125: icmp_seq=2Ttl= AboutTime=1.57Ms

The principle is not very clear. Mark a moment first.

Linux set up IP, you can access the intranet, no access to the external network

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.