NAT設定問題 - Linux

Ivy avatar
By Ivy
at 2009-08-12T17:14

Table of Contents

1. 啟用 ip_forward

vi /etc/sysctl.conf
http://img442.imageshack.us/img442/3861/rhel5master200501010007.png

馬上套用

sysctl -p


或者透過 echo 的方式 (不過這得寫到 rc.local 當中,每次開機就得套用)

http://img10.imageshack.us/img10/1781/rhel5master200501010009.png



2. 透過iptables 設定nat
不知道你的WAN端是透過什麼方式來連出去~
不過根據你提供的資料~ WAN 端應該是以 static 的方式進行連線~
假設架構為 IP分享器 <-> Linux <-> WinXP
那iptables寫法如下:
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -j SNAT \
--to 192.168.1.123


通常RHEL 5的iptables規則預設是沒有的~
而預設的rules的檔案都會存放在 /etc/sysconfig/iptables 這個檔案當中~

所以~
要事先去定義iptables的規則~

service iptables stop
iptables -F
iptables -X
iptables -Z
iptables -L
iptables -P FOREARD ACCEPT (也可以設定成DROP 看你的需求而定)
service iptables save (也可以用 iptables-save)

之後在 vi /etc/sysconfig/iptables 這個檔案
裡頭加入
-t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -j SNAT --to 192.168.1.23


service iptables start
chkconfig iptables on

這樣就可以了~

Good luck~


※ 引述《thorstan1234 (我又斷線了..)》之銘言:
: 請問各位先進
: 我架了一台linux (RHEL5.0)
: 兩張網卡
: eth0對外 192.168.1.123 (透過ip分享器連出去)
: 255.255.255.0
: 192.168.1.1
: eth1對內 192.168.0.254
: 255.255.255
: DNS 168.95.1.1
: 192.168.1.1
: 要用其他台windows 電腦 (用switch接兩台電腦)
: 想要透過eth0 連線到網路
: 192.168.0.5
: 255.255.255.0
: 192.168.0.254
: DNS 168.95.1.1
: 192.168.1.1
: 看了一些書 下了一些指令
: 也有在網路搜尋其他文章
: 但還是沒辦法讓讓他上網 Orz
: linux那台可以正常上網
: 有載入 ip_tables 等mod
: iptable.nat
: echo 1 > /proc/sys/net/ipv4/ip_forward
: [可是net資料夾裡面找不到ipv4的資料夾 不知道下這行指令到底有沒有用 = ="]
: iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
: windows電腦可以ping到switch和linux
: 但是沒辦法對外
: 網路上有很多簡易設定的方法
: 但不知道是不是版本不一樣
: 還是少了什麼步驟
: 東湊湊西補補始終沒辦法成功
: 麻煩了.

--
Tags: Linux

All Comments

Una avatar
By Una
at 2009-08-15T16:13
謝謝

Re: 請問 Ubuntu 要如何設定自動登入

Agatha avatar
By Agatha
at 2009-08-12T13:04
我確定9.04安裝的時候可以勾選自動登入, 我家媽媽就從來不用輸入密碼。 ※ 引述《monicalenphyatkkcity.com.tw ( )》之銘言: : 我的系統是 Ubuntu 8.04 系列的,因為長輩要使用電腦, : 如果需要輸入帳號密碼的話,對他們來說,是很大的障礙。 : 所以想要請教大家 ...

kernek oanic的問題

Rachel avatar
By Rachel
at 2009-08-12T11:08
※ 引述《DerrickRose1 (螺絲)》之銘言: : VFS: Cannot open root device and#34;LABEL=/and#34; or 00:00 : Please append a correct and#34;root=and#34; boot option : kerne ...

kernek oanic的問題

Brianna avatar
By Brianna
at 2009-08-12T10:34
各位好 這台電腦灌的是RH9 本來都用的好好的 不過前兩天有次停電,電腦不正常關機 隔天開機之後,系統就進不去了 畫面停在 VFS: Cannot open root device and#34;LABEL=/and#34; or 00:00 Please append a correct and#34;r ...

bootable 硬碟不能 automount

Thomas avatar
By Thomas
at 2009-08-12T02:23
※ 引述《indept (真人)》之銘言: : ID : 5 : Attribute: Reallocated Sector Count : current : 100 : worst : 100 : threshold: 36 : value : 3 sectors : statu ...

Thinkpad R400裝Ubuntu9.04的無線網路和記憶體

Audriana avatar
By Audriana
at 2009-08-12T01:05
已經試過各種方法了 無線網路還是有問題 03:00.0 Ethernet controller: Atheros Communications Inc. AR242x 802.11abg Wireless PCI Express Adapter (rev 01) 1. hardware manager和官網 ...