QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 885|回复: 3

郁闷。还是nat的问体,求救

[复制链接]
发表于 2005-1-12 15:27:53 | 显示全部楼层 |阅读模式
看完了公社里所有关于nat的帖子后发言
我的网络情况
两台机器
主机A两块网卡
网卡0:192.168.1.1 接adsl了
网卡1:192.168.0.1 接另一台linux主机B了(192.168.0.2)
主机A拨号上网后,想让主机B可以通过主机A上网,让主机A实现NAT功能。

echo "1" > /proc/sys/net/ipv4/ip_forwar
iptables -t nat -A POSTROUTING -o ppp0 -s 192.168.0.0/24 -j MASQUERADE

iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  192.168.0.0/24       anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
这样应该没问体吧,可惜不行,在B上,直接ping公网ip也不行,说明不是dns的问体。
有人说要重新起动network
于是
[root@ ~]# cat /proc/sys/net/ipv4/ip_forward
0
[root@ ~]# service network stop
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
[root@2 ~]# echo "1">/proc/sys/net/ipv4/ip_forward
[root@ ~]# cat /proc/sys/net/ipv4/ip_forward
1
[root@m ~]# service network start
Setting network parameters: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth1: [ OK ]
[root@M ~]# cat /proc/sys/net/ipv4/ip_forward
0
[root@M ~]#
自己又改回去了。。。。


两台均为magiclinux.

主机A
[root@Makelove2 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:E0:4C:53:9B:76
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::2e0:4cff:fe53:9b76/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3973 errors:0 dropped:0 overruns:0 frame:0
TX packets:4120 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3084351 (2.9 Mb) TX bytes:457656 (446.9 Kb)
Interrupt:5 Base address:0xe000

eth1 Link encap:Ethernet HWaddr 52:54:AB:36:B5:89
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::5054:abff:fe36:b589/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:618 (618.0 b)
Interrupt:11 Base address:0xc000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1165 errors:0 dropped:0 overruns:0 frame:0
TX packets:1165 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:66932 (65.3 Kb) TX bytes:66932 (65.3 Kb)

ppp0 Link encapoint-to-Point Protocol
inet addr:221.0.103.48 P-t-P:221.0.64.29 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1
RX packets:3456 errors:0 dropped:0 overruns:0 frame:0
TX packets:3594 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:2977239 (2.8 Mb) TX bytes:346890 (338.7 Kb)
发表于 2005-1-12 17:08:39 | 显示全部楼层
就这几句好像不行
echo "1" > /proc/sys/net/ipv4/ip_forwar
iptables -t nat -A POSTROUTING -o ppp0 -s 192.168.0.0/24 -j MASQUERADE
加上下面试试
iptables -t nat -A POSTROUTING -o ppp0 -s 192.168.0.0/24 -j SNAT --to-source 公网ip
iptables -t nat -A PREROUTING -i ppp0 -d **** -j DNAT --to-destination 192.168.0.0/24
回复

使用道具 举报

 楼主| 发表于 2005-1-12 21:34:29 | 显示全部楼层
iptables -t nat -A PREROUTING -i ppp0 -d **** -j DNAT --to-destination 192.168.0.0/24
****这是什么?代表着什么还是就这么直接输入?
回复

使用道具 举报

发表于 2005-1-12 23:51:20 | 显示全部楼层
你ppp0拿到的公网ip
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-6 17:28 , Processed in 0.045572 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表