我么需要的环境:
sw1为公司出口,192开头的网段为内网也就是公司内部
1动态-------缺点:只能外网访问内网,内网无法访问外网
2静态-------缺点:比如有两个公网ip如果在有两个人上网的时候,第三个人无法上网,由于使用设备不固定所以,外网无法访问内网,内网可以访问外网
3pat---------
如果想使用一键复制导入必须要和我图片的接口ip都一模一样
我们在三层交换上进行以下配置
en
conf t
ip routing
vlan 2
exit
vlan 3
exit
int range f0/1-3
sw mo a
sw a vlan 2
ex
int range f0/6-7
sw mo a
sw a vlan 3
ex
int vlan 1
ip add 192.168.1.254 255.255.255.0
ex
int vlan 2
ip add 192.168.2.254 255.255.255.0
ex
int vlan 3
ip add 192.168.3.254 255.255.255.0
ex
int f0/8
no switchport
ip add 192.168.4.1 255.255.255.0
no shut
ex
ip route 0.0.0.0 0.0.0.0 192.168.4.2
我们的sw1配置为:
en
conf t
int g0/0
ip add 192.168.4.2 255.255.255.0
no shut
ex
int g0/1
ip ad 100.1.1.1 255.255.255.0
no shut
ex
ip route 0.0.0.0 0.0.0.0 100.1.1.2
ip route 192.168.1.0 255.255.255.0 192.168.4.1
ip route 192.168.2.0 255.255.255.0 192.168.4.1
ip route 192.168.3.0 255.255.255.0 192.168.4.1
sw2 为
en
conf t
int g0/0
ip add 100.1.1.2 255.255.255.0
no shut
ex
int g0/1
ip add 200.1.1.1 255.255.255.0
no shut
ex
这样我们的内网就可以进行相互通信了
nat地址转换有这三种,静态,动态和pat
1.动态
动态有两种一个是直接指定把内网转换成公网-这样我们一个主机就配对上一个指定的公网IP
还有一个是把内网设备的端口号配对到公网ip-在公网访问不同服务通过端口寻找为端口进行服务的设备
我们在sw1也就是公司出口进行配置
ip nat inside source static 192.168.3.1 100.1.1.3
把内网的3.1转换成公网ip
ip nat inside source static 192.168.3.2 100.1.1.4
把内网的4.1转换成公网ip
再到接口里放置
int g0/0
ip nat inside
ex
g0/1
ip nat outside
ex
第一种完成了
第二种用一个公网ip去进行端口绑定
ip nat inside source static tcp 192.168.3.1 80 100.1.1.3 80
ip nat inside source static tcp 192.168.3.2 21 100.1.1.3 21
也要在接口上开启和关闭
2.动态转换
access-list 1 permit 192.168.2.0 0.0.0.255
192.168.2.0为要转换的网段
ip nat pool qwe 100.1.1.4 100.1.1.5 netmask 255.255.255.0
这个是使用公网地地址从哪到哪名字为qwe
ip nat inside source list 1 pool qwe
结合到一起
这样内网的主机就能访问外网了,这个只有两个公网ip当一个网段第三个主机上网那就上不去了需要前两个主机其中一个停止使用并待一会
3.pat转换
pat转换也有两种方式
一个是 不管几个公网ip整个网段都可以同时上网
二:和公司的出口绑定所有数据从公司出口出去
1》绑定ip
access-list 2 permit 192.168.1.0 0.0.0.255
ip nat pool asd 100.1.1.6 100.1.1.6 netmask 255.255.255.0
ip nat inside source list 2 pool asd overload
2》绑定接口
access-list 3 permit 192.168.1.0 0.0.0.255
ip nat inside source list 3 interface g0/1
静态
ip nat inside source static 192.168.3.1 100.1.1.3
ip nat inside source static tcp 192.168.3.1 80 100.1.1.3 80
动态
access-list 1 permit 192.168.2.0 0.0.0.255
ip nat pool qwe 100.1.1.4 100.1.1.5 netmask 255.255.255.0
ip nat inside source list 1 pool qwe
pat 转换共用ip
access-list 2 permit 192.168.1.0 0.0.0.255
ip nat pool asd 100.1.1.6 100.1.1.6 netmask 255.255.255.0
ip nat inside source list 2 pool asd overload
pat 端口
access-list 3 permit 192.168.1.0 0.0.0.255
ip nat inside source list 3 interface g0/1