Iptables+keepalived for multi-source address access

Source: Internet
Author: User


Scenario Description:

Client Business Server a:192.168.11.11

Iptables server b:192.168.22.22 (Master) 192.168.22.23 (standby)

vip:192.168.22.41 192.168.22.42

Service-side Business Server c:192.168.33.33

Business Server C to make IP Source address sound, each customer number to have independent access to the source address.

All customer numbers (example: 1-10) are specified in client A's program,

Under normal circumstances, the client number 1-10 that is seen on Server C is the same source address, how to solve this problem?

A forward proxy between a and C can be configured with multiple addresses, and in a program according to the customer number to access different proxy server IP.


This article uses the Snat and Dnat functions in the iptables, and uses the keepalived to make two hot spares.


First, the configuration of keepalived is as follows:

! Configuration File for Keepalived

Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id Iptables33
}

Vrrp_instance Mopin {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 110
Advert_int 1
Track_interface {
Eth0 Weight 5
}
Authentication {
Auth_type PASS
Auth_pass Mopin
}
virtual_ipaddress {
192.168.22.41/24 BRD 192.168.22.255 Dev eth0 label eth0:1
192.168.22.42/24 BRD 192.168.22.255 Dev eth0 label Eth0:2

}
Notify_backup "/usr/local/keepalived/bin/show.sh vip1 Backup"
Notify_master "/usr/local/keepalived/bin/show.sh vip1 Master"
Notify_fault "/usr/local/keepalived/bin/show.sh vip1 Fault"
Smtp_alert
}


Second, iptables configuration:

#Generated by Iptables-save v1.4.7 on Fri Mar 4 16:03:45 2016
*mangle
:P rerouting ACCEPT [881:72,068]
: INPUT ACCEPT [881:72,068]
: FORWARD ACCEPT [0:0]
: OUTPUT ACCEPT [1009:123,804]
:P ostrouting ACCEPT [1009:123,804]
-A prerouting-d 192.168.22.41/32-m conntrack--ctstate new-j MARK--set-xmark 0x41/0xffffffff
-A prerouting-d 192.168.22.42/32-m conntrack--ctstate new-j MARK--set-xmark 0x42/0xffffffff

COMMIT
# completed on Fri Mar 4 16:03:45 2016
# Generated by Iptables-save v1.4.7 on Fri Mar 4 16:03:45 2016
*nat
:P rerouting ACCEPT [0:0]
:P ostrouting ACCEPT [0:0]
: OUTPUT ACCEPT [0:0]
-A prerouting-d 192.168.22.41/32-p tcp-m tcp--dport 10041-j DNAT--to-destination 192.168.33.33:80
-A prerouting-d 192.168.22.42/32-p tcp-m tcp--dport 10042-j DNAT--to-destination 192.168.33.33:80

-A postrouting-m Mark--mark 0x41-j SNAT--to-source 192.168.22.41
-A postrouting-m Mark--mark 0x42-j SNAT--to-source 192.168.22.42

COMMIT
# completed on Fri Mar 4 16:03:45 2016
# Generated by Iptables-save v1.4.7 on Fri Mar 4 16:03:45 2016
*filter
: INPUT ACCEPT [0:0]
: FORWARD ACCEPT [0:0]
: OUTPUT ACCEPT [2024:234,224]
-A input-m state--state related,established-j ACCEPT
-A input-p icmp-j ACCEPT
-A input-p vrrp-j ACCEPT
-A input-p tcp-m tcp--dport 5666-j ACCEPT
-A input-p udp-m UDP--dport 161-j ACCEPT
-A input-i lo-j ACCEPT
-A input-p tcp-m state--state new-m TCP--dport 22-j ACCEPT
-A input-j REJECT--reject-with icmp-host-prohibited
-A forward-m state--state related,established-j ACCEPT
-A forward-s 192.168.0.0/16-j ACCEPT
-A forward-s 10.0.0.0/8-j ACCEPT

-A forward-j REJECT--reject-with icmp-host-prohibited
COMMIT
# completed on Fri Mar 4 16:03:45 2016


Mainly for different VIP address to mangle on the label, to distinguish between different source address.

This article is from the "Autumn Fairy tale" blog, please be sure to keep this source http://wushank.blog.51cto.com/3489095/1747631

Iptables+keepalived for multi-source address access

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.