免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1827 | 回复: 1
打印 上一主题 下一主题

双线服务器的配置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-22 11:12 |只看该作者 |倒序浏览

Quotation
named.conf更新
公司开发网站,为解决南北访问的问题,我把服务器托管到一个双线机房。经过反复调试,终于完成相应的配置。现将配置过程简明记录如下,供大家参考。
一、服务器状态
网通使用第一块网卡(eth0):
IP:218.57.200.242
掩码:255.255.255.0
网关:218.57.200.1
DNS1:202.102.152.3
DNS2:202.102.128.68
电信使用第二块网卡(eth1):
IP:222.173.254.21
掩码:255.255.255.240
网关:222.173.254.17
DNS1:219.146.0.130
DNS2:219.150.32.132
二、配置网卡:
# vi /etc/sysconfig/networking/profiles/default/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=218.57.200.242
NETMASK=255.255.255.0
GATEWAY=218.57.200.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
# vi /etc/sysconfig/networking/profiles/default/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
IPADDR=222.173.254.21
NETMASK=255.255.255.240
GATEWAY=222.173.254.17
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
# 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     tel
设置网通的路由表
# ip route add 218.57.200.0/24 via 218.57.200.242 dev eth0 table cnc
# ip route add 127.0.0.0/8 dev lo table cnc
# ip route add default via 218.57.200.1 dev eth0 table cnc
设置电信的路由表
ip route add 222.173.254.0/24 via 222.173.254.21 dev eth1 table tel
ip route add 127.0.0.0/8 dev lo table tel
ip route add default via 222.173.254.17 dev eth1 table tel
制定策略,让222.173.254.21的回应数据包走电信的路由表路由,218.57.200.242的回应数据包走网通的路由表路由
ip rule add from 222.173.254.21 table tel
ip rule add from 218.57.200.242 table cnc
修改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 218.57.200.242 netmask 255.255.255.0 gw 218.57.200.1
eth1 net 222.173.254.21 netmask 255.255.255.240 gw 222.173.254.17

将从两个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 222.173.254.17
增加出口路由策略,客户端是网通的走网通线路,其余走电信线路。
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
//
// named.conf for Red Hat caching-nameserver
//
options {
  directory "/var/named";
  dump-file "/var/named/data/cache_dump.db";
  statistics-file "/var/named/data/named_stats.txt";
  version "Unsupported on this platform";
  /*
   * If there is a firewall between you and nameservers you want
   * to talk to, you might need to uncomment the query-source
   * directive below.  Previous versions of BIND always asked
   * questions using port 53, but BIND 8.1 uses an unprivileged
   * port by default.
   */
   // query-source address * port 53;
};
//
// a caching only nameserver config
//
controls {
  inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
acl CNC{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;};
view "internal" {
match-clients {10.0.0.8/8;};
   recursion yes;
   zone "." {
  type hint;
  file "named.ca";
};
zone "localhost" IN {
  type master;
  file "localhost.zone";
  allow-update {none;};
};
zone "localdomain" IN {
  type master;
  file "localdomain.zone";
  allow-update {none;};
};
zone "0.0.127.in-addr.arpa" IN {
  type master;
  file "named.local";
  allow-update {none;};
};
zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
  type master;
  file "named.ip6.local";
  allow-update {none;};
};
zone "255.in-addr.arpa" IN {
  type master;
  file "named.broadcast";
  allow-update {none;};
};
zone "0.in-addr.arpa" IN {
  type master;
  file "named.zero";
  allow-update {none;};
};
};
view "cnc" {
match-clients {CNC;};
  recursion yes;
  zone "zhyh.org" {
    type master;
    file "/var/named/zhyh.org.cnc";
      };
zone "200.57.218.in-addr.arpa" {
        type master;
        file "218.57.200.zone";
};
  };
view "other" {
  match-clients {any;};
  recursion no;
  zone "zhyh.org" {
    type master;
    file "/var/named/zhyh.org";
  };
zone "254.173.222.in-addr.arpa" {
        type master;
        file "222.173.254.zone";
};
};
include "/etc/rndc.key";



配置zhyh.org.cnc,对应网通IP
$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
$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做反向解析;
$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,做好虚拟主机设置
# vi /etc/httpd/conf/httpd.conf
NameVirtualHost 218.57.200.242:80
NameVirtualHost 222.173.254.21:80
        ServerName zhyh.org
        DocumentRoot /var/www/html/
        ServerAdmin webmaster@zhyh.org
        ErrorLog logs/zhyh.org-error_log
        CustomLog "|/usr/local/sbin/cronolog /var/log/httpd/zhyh.org-access_log.%Y%m%d" combined
        
                RewriteEngine On
                RewriteRule ^(.*)/htm/(.*)$ $1.php?$2
        
        ServerName www.zhyh.org
        DocumentRoot /var/www/html/zhyh.org
        ServerAdmin webmaster@zhyh.org
        ErrorLog logs/zhyh.org-error_log
        CustomLog "|/usr/local/sbin/cronolog /var/log/httpd/zhyh.org-access_log.%Y%m%d" combined


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/5948/showart_447954.html

论坛徽章:
0
2 [报告]
发表于 2011-12-20 10:14 |只看该作者
很好,,,
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP