1. 网关服务器上两张网卡:
eth0 =》内网172.18.1.240
eth1=》外网211.139.169.X2. 客户端机:
172.18.1.x
3. 网关服务器配置:
打开IP转发功能:
[plain]
view plain
copy
- echo 1 > /proc/sys/net/ipv4/ip_forward
建立nat 伪装
[plain]
view plain
copy
- iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
- iptables -t nat -A POSTROUTING -s 172.18.1.0/22 -o eth1 -j MASQUERADE
建立转发(特定子网的转发)
[plain]
view plain
copy
- iptables -A FORWARD -i eth0 -j ACCEPT
- iptables -A FORWARD -s 172.18.1.0/22 -m state --state ESTABLISHED,RELATED -j ACCEPT
保存iptables 配置
[plain]
view plain
copy
- service iptables save
4. 最简单的网关就配置好了。可以按实际情况加上各种转发规则。
找一台客户机:设置
IP:172.18.1.x/24
GATEWAY(服务器的IP):172.18.1.240
DNS(与服务器的一致):210.21.196.6 221.5.88.88
验证能不能正常访问外部。
OK,到此设置成功了!
5. 更高级的用法:
[plain]
view plain
copy
- #限制特定MAC 地址外部访问:
- iptables -A FORWARD -m mac --mac-source xx:xx:xx:xx:xx:xx -j DROP
- #解封:
- iptables -D FORWARD -m mac --mac-source xx:xx:xx:xx:xx:xx -j DROP
[plain]
view plain
copy
- #限制所有通信:
- iptables -A INPUT -m mac --mac-source xx:xx:xx:xx:xx:xx -j DROP
- #解封:
- iptables -A INPUT -m mac --mac-source xx:xx:xx:xx:xx:xx -j DROP
[plain]
view plain
copy
- #限制特定IP外部访问:
- iptables -A FORWARD -s 192.168.0.x -j DROP
- #解封:
- iptables -D FORWARD -s 192.168.0.x -j DROP
[plain]
view plain
copy
- #限制所有通信:
- iptables -A INPUT -s 192.168.0.x -j DROP
- #解封:
- iptables -D INPUT -s 192.168.0.x -j DROP
查看所有规则:
[plain]
view plain
copy
- iptables -L
- #或者:
- cat /etc/sysconfig/iptables
SSH外部登录安全设定。
SSH默认port:22 可以以ROOT方式登录。更改如下:
1 修改port
[plain]
view plain
copy
- vi /etc/ssh/sshd_config
Port 27481(可以换成不与现有端口相冲突的任意端口)
2 修改限制ROOT方式登录
[plain]
view plain
copy
- vi /etc/ssh/sshd_config
PermitRootLogin no
3保存退出。重启SSH
[plain]
view plain
copy
- Service sshd restart
4 用ssh软件测试是否生效。