Enable centos Intranet machine to access the Internet

Source: Internet
Author: User

Enable centos Intranet machine to access the Internet

Environment: one machine with Internet and Intranet, and the other machine only has Intranet, which by default cannot access the Internet. Both machines are centos Systems

The Internet ip address of the machine with Internet access is 123.221.20.11, and the Intranet ip address is 192.168.15.100.

The Intranet ip address of the Intranet machine is 192.168.15.101.

The setting method is simple:

1. Set iptables rules on machines with Internet access:

Iptables-t nat-a postrouting-s 192.168.15.101-j SNAT -- to 123.221.20.11

// If You Want To Enable Internet access for all machines on the Intranet, replace-s 192.168.15.101

-S 192.168.15.0/255.255.255.0

2. Enable forwarding on a machine with Internet bandwidth

First, check whether it is enabled.

Sysctl-a | grep 'Net. ipv4.ip _ forward'

If the value is 1, it indicates that it has been enabled; otherwise, you need to modify the configuration file/etc/sysctl. conf.

Open the configuration file, find the parameter, and change it

Net. ipv4.ip _ forward = 1

Then run sysctl-p

3. on the Intranet machine, set its gateway to 192.168.15.100

Vim/etc/sysconfig/network-scripts/ifcfg-eth0

Add

GATEWAY = 192.168.15.100

Restart the network service. Service network restart

4. test whether the Intranet machine can access the Internet.

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.