免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: lingg2002

[网络管理] linux策略路由的问题 [复制链接]

论坛徽章:
0
发表于 2004-06-09 20:26 |显示全部楼层

linux策略路由的问题

可如果你做NAT,--to怎么写?那个地址又是哪的地址呢?

如果不做NAT,SNAT还会用在哪里呢?

论坛徽章:
0
发表于 2004-06-09 21:10 |显示全部楼层

linux策略路由的问题

nat可以分为2种,一种是DNAT(改ip数据包头的目的地址),可以用来进行负载均衡,或者ip重定向
一种是SNAT(改ip数据包头的源地址)可以用来进行ip伪装等.
进行nat的设备一般是路由或者firewall.
你的to就是你要把ip数据包头的源地址改到的地址.

不知道讲的对不对

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
发表于 2004-06-10 01:20 |显示全部楼层

linux策略路由的问题

--to 是 please change it to .... 的意思,或理解為 replaced with ... 也行。

SNAT 是"靜態"的指定 replaced with 甚麼 IP ,也就是 --to 所指定的。
MASQUERADE 則是"動態"的根據 routing 判斷後所傳出之界面當時 IP 作修改。

所以為特例嘛,如:在一個 dial-up 連線 ppp0 上,
每次的 IP 都不一樣,用 SNAT 就較難判斷該打甚麼 IP 。
用 MASQUERADE 呢? ----->;管他幹嘛?不用我們操心啊,當時是哪個 IP 就用哪個。

我想,platinum 一直存在一個誤解:
--- 以為從哪個界面出,是 iptables/NAT 決定的。
這大錯特錯,我再講一次:
但無論如何,iptables 並不能決定 packet 從哪送出,
充其量是修改 socket 後改變 routing 結果而已。

若還不理解,那我不再說了...

论坛徽章:
0
发表于 2004-06-10 01:22 |显示全部楼层

linux策略路由的问题

原帖由 "lingg2002" 发表:
nat可以分为2种,一种是DNAT(改ip数据包头的目的地址),可以用来进行负载均衡,或者ip重定向
一种是SNAT(改ip数据包头的源地址)可以用来进行ip伪装等.
进行nat的设备一般是路由或者firewall.
你的to就是你要把ip数据..........


你说得对.
另外纠正前面的一个错误观点:NAT是第三层的操作,与SOCKET无关.

论坛徽章:
0
发表于 2004-06-10 01:33 |显示全部楼层

linux策略路由的问题

原帖由 "網中人" 发表:

我想,platinum 一直存在一個誤解:
--- 以為從哪個界面出,是 iptables/NAT 決定的。

ROUTE和SNAT中的--to不一样,这个我知道,也做过试验,SNAT只不过改变了SOURCE

我想知道的是,MASQUERADE那么灵活,为什么还要用SNAT
即使是静态网络环境,MASQUERADE依然适用,既然这样,为什么还要用SNAT

换句话说,SNAT除了能做NAT以外,还能做什么?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
发表于 2004-06-10 03:49 |显示全部楼层

linux策略路由的问题

原帖由 "JohnBull"]另外纠正前面的一个错误观点:NAT是第三层的操作,与SOCKET无关.[/quote 发表:


若你指其他 NAT "產品",那我不便說甚麼。

不過我們這裡談的是 iptables ,那就會改 socket pair:
source socket (SNAT)
destination socket (DNAT)

要驗正也不難:用多個 client 透過 linux iptables 的 SNAT 連外,
當兩個 client 端 port 相同的時後,抓 iptables 的封包來看即可見分曉...

如下為 man iptables 中關於 NAT 設定的說明:
[quote]   SNAT
       This  target  is only valid in the nat table, in the POSTROUTING chain.
       It specifies that the source address of the packet should  be  modified
       (and  all  future packets in this connection will also be mangled), and
       rules should cease being examined.  It takes one type of option:

       --to-source  ipaddr[-ipaddr][:port-port]
              which can specify a single new source IP address,  an  inclusive
              range  of  IP  addresses, and optionally, a port range (which is
              only valid if the rule also specifies -p tcp or -p udp).  If  no
              port  range  is  specified,  then source ports below 512 will be
              mapped to other ports below 512:  those  between  512  and  1023
              inclusive  will  be  mapped to ports below 1024, and other ports
              will be mapped to 1024 or above. Where possible, no port  alter-
              ation will occur.

       You can add several --to-source options.  If you specify more
              than one source address, either via an address range or multiple
              --to-source options, a simple round-robin (one after another  in
              cycle) takes place between these adresses.

   DNAT
       This  target is only valid in the nat table, in the PREROUTING and OUT-
       PUT chains, and user-defined chains which are only  called  from  those
       chains.  It specifies that the destination address of the packet should
       be modified (and all future packets in this  connection  will  also  be
       mangled),  and rules should cease being examined.  It takes one type of
       option:

       --to-destination ipaddr[-ipaddr][:port-port]
              which can specify a single new destination IP address, an inclu-
              sive  range of IP addresses, and optionally, a port range (which
              is only valid if the rule also specifies -p tcp or -p udp).   If
              no port range is specified, then the destination port will never
              be modified.

       You can add several --to-destination options.  If you specify more
              than one destination address, either via  an  address  range  or
              multiple  --to-destination  options,  a  simple round-robin (one
              after another in cycle) load balancing takes place between these
              adresses.

   MASQUERADE
       This  target  is only valid in the nat table, in the POSTROUTING chain.
       It should only be used with dynamically assigned  IP  (dialup)  connec-
       tions: if you have a static IP address, you should use the SNAT target.
       Masquerading is equivalent to specifying a mapping to the IP address of
       the  interface  the  packet  is going out, but also has the effect that
       connections are forgotten when the interface goes down.   This  is  the
       correct  behavior  when  the  next  dialup is unlikely to have the same
       interface address (and hence any established connections are lost  any-
       way).  It takes one option:

       --to-ports port[-port]
              This  specifies  a  range of source ports to use, overriding the
              default SNAT source port-selection heuristics (see above).  This
              is only valid if the rule also specifies -p tcp or -p udp.

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
发表于 2004-06-10 03:54 |显示全部楼层

linux策略路由的问题

原帖由 "platinum" 发表:

ROUTE和SNAT中的--to不一样,这个我知道,也做过试验,SNAT只不过改变了SOURCE

我想知道的是,MASQUERADE那么灵活,为什么还要用SNAT
即使是静态网络环境,MASQUERADE依然适用,既然这样,为什么还要用SNAT

..........

你有沒見過一台 linux 用 ip alias 綁了多個 IP 在上面?
若見過,再思考一下:
用 MASQUERADE 可否指定用哪個 IP ?
若用 SNAT 呢?
不同的場合會用不同的設定啊...

親愛的朋友,不必懷疑 iptables 的作者比我們笨,凡存在皆有其用。
只有虛心的檢討自己對 iptables 是否了解得足夠?
若還沒夠,那看電影、唱 kara okay、逛百貨公司的時間可以壓縮一下了...  ^_^

论坛徽章:
0
发表于 2004-06-10 07:42 |显示全部楼层

linux策略路由的问题

哎呀,竟然忘记了可以绑定多IP

谢谢网兄指点 ^O^

论坛徽章:
0
发表于 2005-01-27 21:06 |显示全部楼层

linux策略路由的问题

看过帖子以后有这样一个问题:
在一个数据包从外网回到内网的时候(这个包是内网用户的返回包),是先postrouting-->;routing-->;prerouting,还是先prerouting?

论坛徽章:
0
发表于 2005-01-28 10:47 |显示全部楼层

linux策略路由的问题

原帖由 "attiseve" 发表:
看过帖子以后有这样一个问题:
在一个数据包从外网回到内网的时候(这个包是内网用户的返回包),是先postrouting-->;routing-->;prerouting,还是先prerouting?


数据包在链中历遍的顺序不会变,iptables也不会理会数据包的来源
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP