Linux 简单的网络配置练习一

Linux 简单的网络配置练习一

Linux 简单的网络配置练习一

有两个网段:网段一 192.168.6.XX

            网段二 192.168.7.XX

我们将这两个网段通一段Linux Server 连进来,让它们可以互相访问.

网络分布架构图如下:

 

1.       Linux Route Server 配置:

1)添加网卡
#ifconfig
查看当前最大的网卡号,eth0

Last login: Fri Aug 14 11:26:16 2009

[root@sql root]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:D6:7B:EF

inet addr:192.168.6.1 Bcast:192.168.6.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:684 errors:0 dropped:0 overruns:0 frame:0

TX packets:220 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:70820 (69.1 Kb) TX bytes:18565 (18.1 Kb)

Interrupt:5 Base address:0x2000

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:3450 errors:0 dropped:0 overruns:0 frame:0

TX packets:3450 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:235617 (230.0 Kb) TX bytes:235617 (230.0 Kb)

2.修改网卡eth0 的配置信息:vi /etc/sysconfig/network-scripts/ifcfg-eth0

[root@router root]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

BROADCAST=192.168.6.255

IPADDR=192.168.6.2

NETMASK=255.255.255.0

NETWORK=192.168.6.0

ONBOOT=yes

USERCTL=no

PEERDNS=no

TYPE=Ethernet

GATEWAY=192.168.6.2

2.       添加新网卡eth1vi /etc/sysconfig/network-scripts/ifcfg-eth

[root@router root]# vi /etc/sysconfig/network-scripts/ifcfg-eth1

# Please read /usr/share/doc/initscripts-*/sysconfig.txt

# for the documentation of these parameters.

USERCTL=no

PEERDNS=yes

TYPE=Ethernet

DEVICE=eth1

HWADDR=00:0c:29:f5:07:d4

BOOTPROTO=none

NETMASK=255.255.255.0

ONBOOT=yes

IPADDR=192.168.7.2

NETWORK=192.168.7.0

BROADCAST=192.168.7.255

添加上新网卡后,运行命令重新装载网卡

# /etc/init.d/network reload

3.       配置route

192.168.7 网段和192.168.6 网段的都添加进
路由

添加网段:

#route add –net 192.168.6.0 /

>netmask 255.255.255.0 dev eth0

#route add –net 192.168.6.0 /

>netmask 255.255.255.0 dev eth0

添加网关

#route add default gw 192.168.6.2

[root@router root]# route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

192.168.7.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

192.168.6.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1

127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo

0.0.0.0 192.168.6.2 0.0.0.0 UG 0 0 0 eth0

 

设定完route ,执行命令echo “1” > /proc/sys/net/ipv4/ip_forward    启动封包转递功能

[root@router root]# echo “1” > /proc/sys/net/ipv4/ip_forward

4.       PC上的网设定

如:192.168.7 网段的设定


192.168.6 网段的设定


测试:
192.168.6.11这台电脑上 ping 另一个网段的ip: 192.168.7.11

测试成功


Leave a Comment