Use iptables to deploy the LAN environment

Source: Internet
Author: User
As a result of the project's needs, the network environment implemented by virtual machines, one of which serves as the bridge, all other machines are transitioned through the bridge, so it is implemented using the linux Iptablesnat function. The network topology is as follows: for bridge, it has a public IP address, an intranet IP address, and other machines only have an intranet IP address.

As a result of the project's needs, the network environment implemented by virtual machines, one of which serves as the bridge, all other machines are transitioned through the bridge, so the linux Iptables nat function is used.

The network topology is as follows:

 

For bridge, it has a public IP address, an intranet IP address, and other machines only have an intranet IP address, and the bridge intranet IP address is used as the gateway.

To ensure the determination of the network address, first use dhcp to obtain the public IP address, and then use static settings. for how to set the static IP address, refer to Centos (1) to set the static IP address as follows:

 

Currently, the following information is available for bridge posts:

 

Set other intranet machines as follows:

Test the network connectivity, and access the external IP address from the inside can be connected.

Set on bridgeIptablesAs follows:

Test whether iptables works. use iptables-t nat-L. We found that port 22 of 192.168.110.10 exists.

This step is the most critical. at that time, I did not set this step, which caused access to port 1022 of 10.64.70.64 from the outside to fail.

Set net. ipv4.ip _ forwarding in/etc/sysctrl. conf,

So far, iptables has ended to implement the above network architecture. in this process, there is no way to use a lot of content found on the network, this document serves as the basis for future queries.

I also hope it will be useful to others.

Add on 8/12

After we have configured nat, we can test their connectivity, but if it doesn't work, how can we debug it.

First, add the following content to/etc/sysconfig/iptables.

-A prerouting-I eth0-p tcp-j LOG -- log-level warning -- log-prefix "*** nat-statu ***"
Restart iptables
Service iptables restart
In this case, we use the warning method to print every incoming tcp information.

Second, set syslog

Vim/etc/syslog. conf
#2 Add the following content
Kern. warning/var/log/iptables. log
Restart syslog

You can view the connection information in/var/log/iptables. log.

In this way, you can implement simple debug.

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.