Use iproute, iprule, and iptables to configure routing policies
Source: Internet
Author: User
The company's intranet requires 10.0.0.1 gateway to be used within 192.168.0.100 to access the Internet (Telecom). other IP addresses must first add a default route on the Gateway Server to access the Internet using ipv0.0.1 (Netcom, of course, this point is the egress gateway of the vast majority of IP addresses. After iprouteadddefaultgw20.0.0.1, add a route table through iproute. company I requires 10.0.0.1 or earlier for intranet access through the 10.0.0.1 Gateway (China Telecom). other IP addresses use ipv0.0.1 (China Netcom) for Internet access.
First, add a default route on the Gateway Server. of course, this route points to the egress gateway of the vast majority of IP addresses.
Ip route add default gw route 0.0.1
Then add a route table through ip route
Ip route Add table 3 via 10.0.0.1 dev ethX (ethx is the network adapter of 10.0.0.1 and 3 is the route table number)
Add ip Rule rules
Ip rule add Fwmark 3 Table 3 (fwmark 3 is the mark, and table 3 is the top of route table 3. This means that the table 3 route table is used for data marked with 3 in everything)
Later use
IptablesMark the corresponding data
Iptables-a prerouting-t mangle-I eth0-s 192.168.0.1-192.168.0.100 -J MARK -- set-mark 3
Because mangle processing takes precedence over nat and fiter tables, when dependent data packets arrive, they are marked first, and then routed using the corresponding route table through the ip rule, finally, read the route table information and send the data packets to the Gateway.
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