linux NAT 配置實現上網

來源:互聯網
上載者:User

標籤:linux nat 實現上網

1、環境

[[email protected] ~]# lsb_release -a
LSB Version:    :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.10 (Final)
Release:        5.10
Codename:       Final

 

[[email protected] ~]# getconf LONG_BIT
32

 

2.配置IP/DNS等資訊

外網:

# ifconfig eth0 | grep "inet addr"
inet addr:222.47.48.25  Bcast:222.47.48.63  Mask:255.255.255.192

內網:

# ifconfig eth1 | grep "inet addr" 
inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0

DNS:

# cat /etc/resolv.conf
nameserver 222.47.62.142
nameserver 222.47.29.93

 

3.開啟核心轉寄功能

echo 1 > /proc/sys/net/ipv4/ip_forward    //網卡重啟後會恢複為0,所以需要把如下參數更改為“1”

# cat /etc/sysctl.conf | grep ip_forward
net.ipv4.ip_forward = 0

 

4.配置NAT

# iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.255.0 -o eth0 -j SNAT --to-source 222.47.48.25

# iptables -D FORWARD 1

# /etc/init.d/iptables save

# /etc/init.d/iptables restart

 

 

 

 

本文出自 “方寸小山” 部落格,請務必保留此出處http://63638790.blog.51cto.com/513514/1559409

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.