網通使用第一塊網卡(eth0):
IP:210.82.37.149
掩碼:255.255.255.224
網關:210.82.37.158
鐵通使用第二塊網卡(eth1):
IP:222.35.92.242
掩碼:255.255.255.252
網關:222.35.92.241
二、配置網卡:
# vi /etc/sysconfig/networking/profiles/default/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=210.82.37.149
NETMASK=255.255.255.224
GATEWAY=210.82.37.158
TYPE=Ethernet
# vi /etc/sysconfig/networking/profiles/default/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=222.35.92.242
NETMASK=255.255.255.252
GATEWAY=222.35.92.241
TYPE=Ethernet
# vi /etc/sysconfig/networking/profiles/default/route-eth1
GATEWAY0=218.57.200.1
NETMASK0=255.255.255.0
ADDRESS0=218.57.200.242
# vi /etc/sysconfig/networking/profiles/default/resolv.conf
nameserver 202.102.152.3
nameserver 202.102.128.68
三、配置路由表
# vi /etc/iproute2/rt_tables,增加網通和鐵通兩個路由表
252 cnc
251 crtc
設置網通的路由表
ip route add 210.82.37.128/27 via 210.82.37.149 dev eth0 table cnc
ip route add 127.0.0.0/8 dev lo table cnc
ip route add default via 210.82.37.158 dev eth0 table cnc
設置鐵通的路由表
ip route add 222.35.92.240/30 via 222.35.92.242 dev eth1 table crtc
ip route add 127.0.0.0/8 dev lo table crtc
ip route add default via 222.35.92.241 dev eth1 table crtc
制定策略,讓222.35.92.242的回應數據包走鐵通的路由表路由,210.82.37.149的回應數據包走網通的路由表路由
ip rule add from 210.82.37.149 table cnc
ip rule add from 222.35.92.242 table crtc
修改IP轉發文件
# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
kernel.sysrq = 0
設置靜態路由表文件
# vi /etc/sysconfig/static-routes
eth0 net 210.82.37.149 netmask 255.255.255.224 gw 210.82.37.158
eth1 net 222.35.92.242 netmask 255.255.255.252 gw 222.35.92.241
將從兩個WAN口出去的數據包進行IP偽裝masquerade
# /sbin/modprobe ip_conntrack_ftp
# /sbin/modprobe ip_nat_ftp
# /sbin/iptables -t nat -A postrouting -o eth0 -j masquerade
# /sbin/iptables -t nat -A postrouting -o eth1 -j masquerade
設置默認網關為網通
# route add default gw 210.82.37.158
增加出口路由策略,客戶端是鐵通的走鐵通線路,其余走網通線路。
CODE:
ip rule add to 121.16.0.0/13 table cnc
ip rule add to 121.24.0.0/14 table cnc
ip rule add to 121.28.0.0/15 table cnc
ip rule add to 121.30.0.0/16 table cnc
ip rule add to 121.31.0.0/16 table cnc
其余省略...
刷新路由表
ip route flush cache
四、配置DNS
在服務器上配置自己的DNS解析,將域名服務器商處的域名解析指向服務器。
這樣,來自網通的查詢,將反饋網站網通的IP,其余反饋電信的IP。
配置named.conf
CODE:
view "cnc" {
match-clients {121.16.0.0/13;121.24.0.0/14;121.28.0.0/15;121.30.0.0/16;121.31.0.0/16;121.47其余省略...;}
recursion yes;
zone "zhyh.org" {
type master;
file "/var/named/zhyh.org.cnc";
};
};
view "other" {
match-clients { any; };
recursion no;
zone "zhyh.org" {
type master;
file "/var/named/zhyh.org";
};
};
配置zhyh.org.cnc,對應網通IP
CODE:
$TTL 86400
@ IN SOA zhyh.org. root (
2006111800 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS zhyh.org.
IN A 218.57.200.242
IN MX 10 mail
www IN A 218.57.200.242
ns1 IN A 218.57.200.242
ns IN A 222.173.254.21
mail IN A 218.57.200.242
1 IN PTR localhost.
配置zhyh.org,對應電信IP
CODE
$TTL 86400
@ IN SOA zhyh.org. root (
2006111800 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS zhyh.org.
IN A 222.173.254.21
IN MX 10 mail
www IN A 222.173.254.21
ns IN A 222.173.254.21
ns1 IN A 218.57.200.242
mail IN A 222.173.254.21
1 IN PTR localhost.
配置222.173.254.zone、218.57.200.zone做反向解析;
CODE:
$TTL 86400
@ IN SOA zhyh.org. root.zhyh.org. (
2006111813
3600
7200
3600000
86400 )
IN NS localhost.
242 IN PTR www.zhyh.org.
242 IN PTR ns1.zhyh.org.
242 IN PTR mail.zhyh.org.
五、配置apache,做好虛擬主機設置
CODE
# vi /etc/httpd/conf/httpd.conf
NameVirtualHost 218.57.200.242:80
NameVirtualHost 222.173.254.21:80
<VirtualHost 222.173.254.21:80 218.57.200.242:80>
ServerName zhyh.org
DocumentRoot /var/www/html/
ServerAdmin [email protected]
ErrorLog logs/zhyh.org-error_log
CustomLog "|/usr/local/sbin/cronolog /var/log/httpd/zhyh.org-access_log.%Y%m%d" combined
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/htm/(.*)$ {GetProperty(Content)}.php?$2</IfModule></VirtualHost>
ServerName www.zhyh.org
DocumentRoot /var/www/html/zhyh.org
ServerAdmin [email protected]
ErrorLog logs/zhyh.org-error_log
CustomLog "|/usr/local/sbin/cronolog /var/log/httpd/zhyh.org-access_log.%Y%m%d" combined</VirtualHost>