Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1446242
  • 博文数量: 463
  • 博客积分: 10540
  • 博客等级: 上将
  • 技术积分: 5450
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-12 08:30
文章分类

全部博文(463)

文章存档

2014年(2)

2012年(14)

2011年(42)

2010年(18)

2009年(78)

2008年(35)

2007年(182)

2006年(92)

我的朋友

分类: LINUX

2007-09-04 20:01:06

一,配置前的准备:

1Linux版本:我的是(企业版,至于红帽9已经不能得到升级和技术支持,所以现在都用企业版。):

[root@tpwb /]# uname -r

2.6.9-34.EL(版本内核)

2IPTABLES版本:

[root@tpwb ~]# iptables -v
iptables v1.2.11: no command specified
Try `iptables -h' or 'iptables --help' for more information.

如果没有安装,安装一下,在次我不讲如何安装IPTABLS,

3,远程软件

SecureCRT5,去百度搜索一下多的事。也可以从我网吧的网页下载。

4,命令术语的了解:

要用到的命令:iptables,vi,route,cat,echo,reboot,ntsysv.

5,相关术语:

什么是NAT,及工作原理.linux下IPTABLES防火墙的基本了解,配置.

二,开始配置

配置NAT采用双网卡(也可用单网卡,但不推荐),如何配置网卡ip,看我的另一篇文章:http://blog.chinaunix.net/u/30548/showart.php?id=244176

下面看一下我的网卡IP配置情况

[root@tpwb network-scripts]# cat ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
BROADCAST=211.101.46.255
HWADDR=4C:00:10:59:6B:20
IPADDR=211.101.46.251
NETMASK=255.255.255.0
NETWORK=211.101.46.0
ONBOOT=yes
TYPE=Ethernet

[root@tpwb network-scripts]# cat ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.1
NETMASK=255.255.255.0
HWADDR=4C:00:10:10:03:55

我才用的是固定IP,

外网IP:211.101.46.251

内网IP是:192.168.1.1

在来看一下DNS和网关

[root@tpwb ~]# cat /etc/resolv.conf

nameserver 192.168.1.1   内网DNS地址
nameserver 202.106.0.20  外网DNS地址

[root@tpwb /]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=tpwb
GATEWAY=211.101.46.1    你的网关(211.101.46.251的网关)

 

[root@tpwb sysconfig]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
211.101.46.0    *               255.255.255.0   U     0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth1
169.254.0.0     *               255.255.0.0     U     0      0        0 eth1
default      211.101.46.1    0.0.0.0     UG    0      0      0 eth0

保证default是 211.101.46.1

 

下面我们要确定一下DNS是否安装,为要DNS呢?其实也可以不要,但这里有个问题,有人在设置DNS时,

设置成 192.168.1.1 IPTABLES配置没有问题,其他也没有问题,就是上不了网!!其实就是因为DNS配置成192.168.1.1了,你该成202.106.0.20就好了,就不能该成192.168.1.1了吗!当然不是你只要安装DNS,并且把它开启就可以了!!!也有人说要配置caching-only dns,但经过我实验,不配置也可以!

[root@tpwb ~]# service named restart
停止 named:
启动 named:                                               [  确定  ]

好到现在前期准备工作差不多了!
 

我的是固定IP地址,所以输入

[root@tpwb ~]#iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to 211.101.46.251


 

你对照着写就行了 不同之处可能会在,eth0(外网接口)看是否和你一样,还有IP地址,私网IP(192.168.1.0/24)和公网IP地址(211.101.46.251)

工作原理我就不说了,自己去找资料看看吧!!

 

现在在客户端配置好ip地址和网关,dns

如:ip地址:192.168.1.2

   子网掩码:255.255.255.0

   网关:192.168.1.1

   DNS:192.168.1.1

然后ping一下192.168.1.1看能否ping通.

在ping 211.101.46.1 看能否ping通 不能对吧!


还要打开ip转发功能.

[root@tpwb ~]#echo 1 > /proc/sys/net/ipv4/ip_forward

 

在ping一次,ok 了

看看能不能上网,不能,还差一点!就是IPTABLES设置

[root@tpwb ~]#iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT

[root@tpwb ~]#iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
允许DNS服务端口的tcp,udp数据包流出

 

在试一次,好了吧!

如果想让所有的配置重起后依然起作用呢,好继续

1,要把IPTABLES的配置保存.

 [root@tpwb ~]#/etc/rc.d/init.d/iptables save

2, [root@tpwb rc.d]# vi /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
echo 1 > /proc/sys/net/ipv4/ip_forward      看这一行,是添加的!

~
~

保存,退出.

3,

[root@tpwb ~]# ntsysv
ntsysv 1.3.13.3 - (C) 2000-2001 Red Hat, Inc.                                  
                                                                               
                       lqqqqqqqqqqqqu 服务 tqqqqqqqqqqqqk                      
                       x                                x                      
                       x 您想自动启动哪些服务?         x                      
                       x                                x                      
                       x   [ ] FreeWnn             #    x                      
                       x   [ ] NetworkManager      a    x                      
                       x   [*] acpid               a    x                      
                       x   [ ] amanda              a    x                      
                       x   [ ] amandaidx           a    x                      
                       x   [ ] amd                 a    x                      
                       x   [ ] amidxtape           a    x                      
                       x   [*] anacron             a    x                      
                       x                                x                      
                       x    lqqqqqqk       lqqqqqqk     x                      
                       x    x 确定 x       x 取消 x     x                      
                       x    mqqqqqqj       mqqqqqqj     x                      
                       x                                x                      
                       x                                x                      
                       mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj                      
                                                                               
                                                                               
可获取关于某项服务的详情。       

在named,iptables的[]里点空格见出现*号后,确定,表示开机自动加载!

 

重起
[root@tpwb rc.d]# reboot
阅读(670) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~