四:NAT功能舉例:
實驗結構:在外地機房存在一臺ROS的有PPTP ***服務器
實現功能:假定當從本地訪問所需資源出現延時過高或者線路不穩定時,通過撥號連接至***服務後,從***服務器所在的ISP做中轉,同時利用***服務器的NAT功能對不同的***授
權用戶進行不同的訪問限制,同時***服務器只具備單個網卡接口
本地路由器只需要實現正常共享上網(實現“ROS菜鳥系列1”功能)即可,
外地***服務器的構建:
實現第一步:先構建***服務器:
[admin@MikroTik] /interface> print
Flags: D - dynamic, X - disabled, R - running, S - slave
# NAME TYPE MTU
0 R ether1 ether 1500
[admin@MikroTik] /interface> set 0 name=wan
[admin@MikroTik] > interface print
Flags: D - dynamic, X - disabled, R - running, S - slave
# NAME TYPE MTU
0 R wan ether 1500
[admin@MikroTik] > ip address add address=211.2.123.42/28 interface=wan
[admin@MikroTik] > ip address print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK BROADCAST INTERFACE
0 211.2.123.42/28 211.2.123.32 211.2.123.47 wan
[admin@MikroTik] > ip route
[admin@MikroTik] /ip route> add gateway=211.2.123.33
[admin@MikroTik] /ip route> print
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC G GATEWAY DISTANCE IN..
0 A S 0.0.0.0/0 r 211.2.123.33 1 wan
1 ADC 211.2.123.32/28 211.2.123.42 0 wan
[admin@MikroTik] > ip pool
[admin@MikroTik] /ip pool> add name=limit ranges=192.168.100.2-192.168.100.254
[admin@MikroTik] /ip pool> add name=nolimit ranges=192.168.200.2-192.168.200.254
[admin@MikroTik] /ip pool> print
# NAME RANGES
0 limit 192.168.100.2-192.168.100.254
1 nolimit 192.168.200.2-192.168.200.254
增加地址池,爲不同的授權用戶動態分配不同的地址段
[admin@MikroTik] /ppp profile> add name=limitprofiles local-address=192.168.100.1 remote
-address=limit dns-server=61.139.2.69 idle-timeout=00:10:00 rate-limit=512K/512K only-on
e=yes
[admin@MikroTik] /ppp profile> add name=nolimitprofiles local-address=192.168.200.1 remo
te-address=nolimit dns-server=61.139.2.69 idle-timeout=00:10:00 rate-limit=1M/1M only-on
e=yes
[admin@MikroTik] /ppp profile> print
Flags: * - default
0 * name="default" use-compression=default use-vj-compression=default
use-encryption=default only-one=default change-tcp-mss=yes
1 name="limitprofiles" local-address=192.168.100.1 remote-address=limit
idle-timeout=10m use-compression=default use-vj-compression=default
use-encryption=default only-one=yes change-tcp-mss=default rate-limit=512K/512K
dns-server=61.139.2.69
2 name="nolimitprofiles" local-address=192.168.200.1 remote-address=nolimit
idle-timeout=10m use-compression=default use-vj-compression=default
use-encryption=default only-one=yes change-tcp-mss=default rate-limit=1M/1M
dns-server=61.139.2.69
3 * name="default-encryption" use-compression=default use-vj-compression=default
use-encryption=yes only-one=default change-tcp-mss=yes
添加***用戶屬性,建立不同的用戶類型
[admin@MikroTik] /ppp profile> ..
[admin@MikroTik] /ppp> secret
[admin@MikroTik] /ppp secret> add name=user1 password=user1 profile=limitprofiles service=pptp
[admin@MikroTik] /ppp secret> add name=user2 password=user2 profile=nolimitprofiles service=pptp
[admin@MikroTik] /ppp secret> print
Flags: X - disabled
# NAME SERVICE CALLER-ID PASSWORD PROFILE REMOTE-ADDRESS
0 user1 pptp user1 limitprofiles
1 user2 pptp user2 nolimitpro...
[admin@MikroTik] /interface pptp-server server> set enabled=yes authentication=pap,chap,mschap1,mschap2
[admin@MikroTik] /interface pptp-server server> print
enabled: yes
max-mtu: 1460
max-mru: 1460
mrru: disabled
authentication: pap,chap,mschap1,mschap2
keepalive-timeout: 30
default-profile: default-encryption
[admin@MikroTik] /interface pptp-server server> /
[admin@MikroTik] > ip firewall address-list
[admin@MikroTik] /ip firewall address-list> add list=qq address=202.104.129.251-202.104.129.254
[admin@MikroTik] /ip firewall address-list> add list=qq address=218.18.95.160-218.18.95.227
[admin@MikroTik] /ip firewall address-list> add list=qq address=202.96.170.163-202.96.170.166
[admin@MikroTik] /ip firewall address-list> print
Flags: X - disabled, D - dynamic
# LIST ADDRESS
0 qq 202.104.129.251-202.104.129.254
1 qq 218.18.95.160-218.18.95.227
2 qq 202.96.170.163-202.96.170.166
添加地址列表
[admin@MikroTik] /ip firewall nat> add chain=srcnat src-address=192.168.200.0/24 action=masquerade out-interface=wan
[admin@MikroTik] /ip firewall nat> add chain=srcnat src-address=192.168.100.0/24 dst-address-list=qq action=masquerade out-interface=wan
[admin@MikroTik] /ip firewall nat> print
Flags: X - disabled, I - invalid, D - dynamic
0 chain=srcnat action=masquerade src-address=192.168.200.0/24 out-interface=wan
1 chain=srcnat action=masquerade src-address=192.168.100.0/24 dst-address-list=qq
out-interface=wan
利用NAT分類不同用戶類型訪問不同資源
以上的例子是所有使用limitprofile用戶組的用戶,在進行***撥號授權通過認證後,只能通過***線路去訪問目標地址爲QQ列表裏面的資源,無法利用***線路去訪問其他的資源,
ROS的操作員可以通過對QQ地址列表裏面目標地址的添加和刪減,從而實現授權用戶對不同目標地址的訪問限制。
善用NAT與其他策略的配合使用,可以實現其他的更多功能,如:上下行的數據分流等