【需求】
掌握Red Hat Linux下的配置网络地址和网络安全的方法。
【系统及软件环境】
操作系统:Red Hat Linux
【实验配置文件及命令】
1.命令: ifconfig ifdown ifup route
2. 命令:使用echo配置/proc/sys/net/ipv4下的icmp_echo-ignore_all和ip_default_ttl来增加系统的安全性。
【实验步骤】
1. 在虚拟机vmware打开后,首先为linux系统添加一块虚拟网卡,再打开linux系统。
2. 设置网卡eth0的地址
[root@localhost ~]# ifconfig eth0 192.168.1.180netmask 255.255.255.0设置网卡eth0的IP地址
[root@localhost ~]# route add -net 192.168.1.0netmask 255.255.255.0 dev eth0
[root@localhost ~]# route add default gw192.168.1.1 设置网卡网关地址
[root@localhost ~]# vi /etc/resolv.conf设置DNS地址
search localdomain
nameserver 202.103.24.68
nameserver 202.103.44.150
[root@localhost ~]# ifconfig eth0 查看更改后的地址
eth0 Link encap:Ethernet HWaddr 00:0C:29:C9:D5:C5
inet addr:192.168.1.180 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec9:d5c5/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:241 errors:0 dropped:0 overruns:0 frame:0
TXpackets:43 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:17877 (17.4 KiB) TX bytes:11449(11.1 KiB)
[root@localhost ~]# ping www.163.com
PING 163.xdwscache.glb0.lxdns.com (219.138.39.150) 56(84) bytes of data.
64 bytes from 219.138.39.150: icmp_seq=1 ttl=56time=66.6 ms
3. 为网卡设置第二个IP地址
[root@localhost ~]# ifconfig eth0:1 192.168.1.181netmask 255.255.255.0该网卡再设一个IP
[root@localhost ~]# ifconfig eth0:1 查看设置的第二个地址
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:C9:D5:C5
inet addr:192.168.1.181 Bcast:192.168.1.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
4. 使用配置文件/etc/sysconfig/network-scripts/ ifcfg-eth0设置IP地址,并且为第二块网卡设置IP地址。
[root@localhost ~]# cd/etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-eth0 ifdown-ipsec ifdown-sl ifup-ipsec ifup-ppp net.hotplug
[root@localhost network-scripts]# viifcfg-eth0 使用配置文件设置IP地址
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
ONBOOT=yes
HWADDR=00:0c:29:c9:d5:c5
NETMASK=255.255.255.0
IPADDR=192.168.1.170
GATEWAY=192.168.1.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
[root@localhost network-scripts]# servicenetwork restart重新启动网卡
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]
[root@localhost network-scripts]# ifconfig eth0 查看IP地址设置好了没
[root@localhost ~]# ifconfig eth1 查看第二块网卡的MAC地址
eth1 Link encap:Ethernet HWaddr 00:0C:29:C9:D5:CF
BROADCAST MULTICAST MTU:1500 Metric:1
RXpackets:0 errors:0 dropped:0 overruns:0 frame:0
TXpackets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:19 Base address:0x20a4
[root@localhost network-scripts]# vi ifcfg-eth1 同样的方法配置第二块网卡
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth1
ONBOOT=yes
HWADDR=00:0c:29:c9:d5:cf
NETMASK=255.255.255.0
IPADDR=192.168.1.191
GATEWAY=192.168.1.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
[root@localhost network-scripts]# ifdown eth0 关闭第一块网卡
[root@localhost network-scripts]# ifdown eth1
[root@localhost network-scripts]# ifup eth1 使用第二块网卡
[root@localhost network-scripts]# ping www.wtc.edu.cn 网络同样可以用
PING www.wtc.edu.cn (61.183.207.195) 56(84) bytes of data.
64 bytes from 61.183.207.195: icmp_seq=1 ttl=121time=109 ms
[1]+ Stopped pingwww.wtc.edu.cn
5.使用/proc/sys/net/ipv4下的icmp_echo-ignore_all防止ping,使用echo将数值“0”改为“1”。
echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all
验证实验结果 ping 本机IP 查看结果
实验完成后
echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all 还原
6.使用/proc/sys/net/ipv4下的ip_default_ttl改变TTL,使用echo将数值“64”改为其它数值。
echo 128 > /proc/sys/net/ipv4/ip_default_ttl
验证实验结果 ping 本机IP 查看结果,观察TTL值。