[网络管理] 请教:单机上作iptables是否需要启动nat模块?

weixin_38058520 weixin_38058520 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

想了解一下,我想自己写一个适合单机上网的脚本
通过电信LAN上网,就一台机子。该怎么设,我的机子也没有一个服务器
我希望尽量简洁
iptables.rule如下

#[root@test root]# mkdir -p /usr/local/virus/iptables
#[root@test root]# cd /usr/local/virus/iptables
#[root@test iptables]# vi iptables.rule
#!/bin/bash

# 0.0 var define
EXTIF="ppp0"
INIF="eth0"
INNET="192.168.0.0/24"

# 1.0 test kernal version
  kver=`uname -r | cut -c 1-3`
  if [ "$kver" != "2.4" ] && [ "$kver" != "2.5" ] && [ "$kver" != "2.6" ]; then
        echo "Your Linux Kernel Version may not be suported by this script!"
        echo "This scripts will not be runing"
        exit
  fi
  ipchains=`lsmod | grep ipchains`
  if [ "$ipchains" != "" ]; then
        echo "unload ipchains in your system"
        rmmod ipchains 2> /dev/null
  fi

# 2.0 load moudles
  PATH=/sbin:/bin:/usr/sbin:/usr/bin
  export PATH EXTIF INIF INNET EXTADDR WEBSERVADDR GATEWAY
  modprobe ip_tables            > /dev/null 2>&1
  modprobe iptable_nat          > /dev/null 2>&1
  modprobe ip_nat_ftp           > /dev/null 2>&1
  modprobe ip_nat_irc           > /dev/null 2>&1
  modprobe ip_conntrack         > /dev/null 2>&1
  modprobe ip_conntrack_ftp     > /dev/null 2>&1
  modprobe ip_conntrack_irc     > /dev/null 2>&1

# 3.0 first clear all iptable rules
  /sbin/iptables -F
  /sbin/iptables -X
  /sbin/iptables -Z
  /sbin/iptables -F -t nat
  /sbin/iptables -X -t nat
  /sbin/iptables -Z -t nat
#  /sbin/iptables -P INPUT   ACCEPT
  /sbin/iptables -P INPUT   DROP
  /sbin/iptables -P OUTPUT  ACCEPT
  /sbin/iptables -P FORWARD ACCEPT
  /sbin/iptables -t nat -P PREROUTING  ACCEPT
  /sbin/iptables -t nat -P POSTROUTING ACCEPT
  /sbin/iptables -t nat -P OUTPUT      ACCEPT

# 4.0 NAT
  /sbin/iptables -A INPUT -i lo -j ACCEPT
  if [ "$INIF" != "" ]; then
        /sbin/iptables -A INPUT -i $INIF -j ACCEPT
        echo "1" > /proc/sys/net/ipv4/ip_forward
        /sbin/iptables -t nat -A POSTROUTING -s $INNET -o $EXTIF -j MASQUERADE
  fi

# 5.0 allow icmp and established
  /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  AICMP="0 3 3/4 4 11 12 14 16 18"
  for tyicmp in $AICMP
  do
        /sbin/iptables -A INPUT -i $EXTIF -p icmp --icmp-type $tyicmp -j ACCEPT
  done

# 6.0 Allow services
  /sbin/iptables -A INPUT -p TCP -i $EXTIF --dport  22 -j ACCEPT        # SSH
  /sbin/iptables -A INPUT -p TCP -i $EXTIF --dport  25 -j ACCEPT        # SMTP
  /sbin/iptables -A INPUT -p UDP -i $EXTIF --dport  53 -j ACCEPT        # DNS
  /sbin/iptables -A INPUT -p TCP -i $EXTIF --dport  53 -j ACCEPT        # DNS
  /sbin/iptables -A INPUT -p TCP -i $EXTIF --dport  80 -j ACCEPT        # WWW
  /sbin/iptables -A INPUT -p TCP -i $EXTIF --dport 110 -j ACCEPT        # POP3
  /sbin/iptables -A INPUT -p TCP -i $EXTIF --dport 113 -j ACCEPT        # auth
各位看看,能用不,哪些还可以不用
我的linux是FC4,因为想稍微研究下,所以不用系统自己的设置工具,谢谢指教
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部