Linux虚拟机做网关实现局域网上网
虚拟机linux
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:B5:69:9F
inet addr:192.168.26.127 Bcast:192.168.26.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feb5:699f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3334 errors:0 dropped:0 overruns:0 frame:0
TX packets:4351 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:268560 (262.2 KiB) TX bytes:1043311 (1018.8 KiB)
Interrupt:19 Base address:0x2000
eth1 Link encap:Ethernet HWaddr 00:0C:29:B5:69:A9
inet addr:192.168.100.2 Bcast:192.168.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feb5:69a9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11682 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:743559 (726.1 KiB) TX bytes:1070 (1.0 KiB)
Interrupt:18 Base address:0x2080
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:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:336 (336.0 b) TX bytes:336 (336.0 b)
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.26.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.26.2 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]# iptables -vnL -t nat
Chain PREROUTING (policy ACCEPT 785 packets, 39223 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 2 packets, 142 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 2 packets, 142 bytes)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE all -- * * 192.168.1.0/24 0.0.0.0/0
1 60 MASQUERADE all -- * * 192.168.100.0/24 0.0.0.0/0
开始启用转发和nat,实现内外网的路由和NAT转换
[root@localhost root]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@localhost root]# iptables -t filter -F
[root@localhost root]# iptables -t nat -F
[root@localhost root]# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
[root@localhost root]# echo 1 > /proc/sys/net/ipv4/ip_forward
将xp的网关设为linux的ip192.168.1.13,
记得每次修改IP设置之后要重启网卡,并且重新启动转发
echo 1 > /proc/sys/net/ipv4/ip_forward
做完linux虚拟机网关的实验后,关闭vmware回到xp中连接adsl,报错:域上的用户名/密码错误.禁用本地连接发现死在那里了,启用的时候报连接失败.只能重启看看了,谁知道就停在那里了,不耐烦就按了reset.发现在选择系统的那个地方停住了,选择进入安全模式也是停在那个地方.重复若干次都不行.害怕,懊恼,郁闷….难道要重新装系统??拿出系统盘,放入光驱,还是觉得不甘心,准备尝试一下,仍然停在那个地方,把插着的U盘拔了,竟然就进去了.不由得长嘘一口气,一场虚惊啊…佛祖保佑….
不过实验几次后发现确实有这个问题,修改了本地连接之后,再用adsl连接会报域上的用户名/密码错误.没办法只好把modem重启了.
阅读(1941) | 评论(0) | 转发(0) |