cisco路由器上作端口映射

測試環境:服務器

  cisco路由器內網接口f0/1: 192.168.1.1 255.255.255.0
 
  外網接口f0/0: 10.0.0.1 255.255.255.0
 
  服務器ip:192.168.1.100
 
  首先到路由器上配置:
 
  Router>en #進入特權模式
 
  Router#conf t #進入全局配置模式
 
  Enter configuration commands, one per line. End with CNTL/Z.
 
  Router(config)#access-list 1 permit 192.168.1.0 0.0.0.255 #創建訪問控制列表準備作nat轉換
 
  Router(config)#ip nat inside source list 1 interface f0/0 #創建NAT轉換,將192.168.1.0的地址轉換爲接口f0/0的地址
 
  Router(config)#int f0/1 #進入接口模式
 
  Router(config-if)#ip nat inside #設定f0/1爲NAT內部接口
 
  Router(config-if)#int f0/0 #進入F0/0的接口模式
 
  Router(config-if)#ip nat outside #設定F0/0爲NAT外部接口
 
  Router(config-if)#exit
 
  Router(config)#
 
  此時已經啓用了NAT,內網能夠上網了。
 
  如今開始端口映射,讓外網訪問內網服務器:
 
  Router(config)#ip nat inside source static tcp 192.168.1.100 5631 10.0.0.1 5631 extendable
 
  Router(config)#ip nat inside source static tcp 192.168.1.100 5632 10.0.0.1 5632 extendable #由於10.0.0.1這個地址已經應用在f0/0接口上並作了NAT轉換的地址,這裏必須加上extendable這個關鍵字,不然報錯。若是用另外的外網ip好比10.0.0.2,在這裏就能夠不加extendable。
 
  如今外網的機器能夠訪問內網了。
 
  命令show ip nat translations能夠查看nat轉換狀況
 
  show run也能夠找到相關配置
 
  Router(config)#exit #退出全局配置模式,到特權模式下使用show命令
 
  Router#sho ip nat translations
 
  Pro Inside global Inside local Outside local Outside global
 
  tcp 10.0.0.1:23 192.168.1.100:23 --- ---
 
  tcp 10.0.0.1:23 192.168.1.100:23 10.0.0.2:48268 10.0.0.2:48268
 
  tcp 10.0.0.1:5631 192.168.1.100:5631 --- ---
 
  tcp 10.0.0.1:5632 192.168.1.100:5632 --- ---
 
  附:要刪除哪條命令只要在命令前加 no 便可
 
  補充: 你telnet的是5631端口,而服務器的telnet端口是23
 
  你要telnet到服務器的5631端口就必須改服務器的telnet端口,在註冊表改,服務器的防火牆也要打開相應端口。
 
  若是你不改服務器端口也能夠將5631的端口映射到服務器的23端口,命令以下:
 
  Router(config)#ip nat inside source static tcp 192.168.1.100 23 10.0.0.1 5631 extendable
 
  要先刪掉5631到5631的映射,命令以下:
 
  Router(config)#no ip nat inside source static tcp 192.168.1.100 5631 10.0.0.1 5631 extendable
 
  不改服務器端口就必須將外網ip的5631端口映射到服務器的23端口。而後你telnet ip 5631 其實就是telnet服務器的23端口