關於LINUX NAT和連接埠轉寄的配置

來源:互聯網
上載者:User

標籤:linux   nat   連接埠轉寄   

一、背景:

linux (ubuntu) 雙網卡伺服器作WEB、路由、DHCP伺服器。

eth2對外:10.1.1.244/254  

eth3對內:192.178.1.254/20

內網說明:192.178.0.1/20  gw:192.178.1.254   

XEN-SERVER:192.178.1.100/20  管理連接埠443,建立虛擬機器,網路模式為橋接。

二、網路設定方案:

內網通過NAT方式訪問外網,XEN-SERVER通過10.1.1.244:8443管理。

三、配置說明:

1.244機器開啟iptables並作以下配置 

#清除filter表規則   

iptables -Fiptables -Xiptables -Z

#清除nat表規則 

iptables -t nat -Fiptables -t nat -Xiptables -t nat -Z

#nat 轉寄

iptables –t nat –A POSTROUNTING –s 192.178.0.0/20 –o eht2 –j MASQUERADE

 
#XENSERVER的管理連接埠映射

iptables –t nat –A PREROUTING –i eth2 –p tcp –dport 8443 –j DNAT–to-destination 192.178.1.100:443

 

2.儲存iptables 配置

#建立/etc/iptables.up.rules 檔案,並修改許可權

vim /etc/iptables.up.ruleschmod 777  iptables.up.rules

#將iptables配置儲存

iptables-save > /etc/iptables.up.rules

#找到網路設定檔  

vim /etc/network/interfaces

#外網eht2後面添加,隨網卡啟動生效   

pre-up iptables-restore < /etc/iptables.up.rules

附iptables.up.rules  注意幾個ACCEPT上面沒說,我預設是全放開的。

*nat:PREROUTING ACCEPT [632:40162]:INPUT ACCEPT [158:11837]:OUTPUT ACCEPT [1:328]:POSTROUTING ACCEPT [1:328]-A PREROUTING -i eth2 -p tcp -m tcp --dport 8443 -j DNAT --to-destination 192.168.1.100:443-A POSTROUTING -s 192.178.0.0/20 -o eth2 -j MASQUERADECOMMIT# Completed on Mon Mar 30 10:55:20 2015# Generated by iptables-save v1.4.12 on Mon Mar 30 10:55:20 2015*filter:INPUT ACCEPT [60769:14812609]:FORWARD ACCEPT [32923:35214235]:OUTPUT ACCEPT [52652:9629979]COMMIT


關於LINUX NAT和連接埠轉寄的配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.