LINUX 配置网络

本文介绍了在Red Hat Linux系统中配置网络地址和增强网络安全的方法,包括使用ifconfig、route命令设置IP地址、网关和DNS,通过修改/proc/sys/net/ipv4的参数增强系统安全,以及通过配置文件设置静态IP。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【需求】

掌握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值。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值