RHEL6网络相关配置

简介:

 ·    /etc/hosts

这个文件用于设置主机名与  IP  映射关系,为那些无法通过其它方式  ( 如通过  DNS  服务器 解析的主机名进行解析 
 
  1. [root@rhel6 ~]# cat /etc/hosts 
  2. 127.0.0.1  localhost.localdomain   localhost 
  3. 192.168.1.119 rhel6.xfcy.org       rhel6 
  4. 192.168.1.90  rhel5.xfcy.org       rhel5 
  5. 192.168.1.11  rhel5-1.xfcy.org     rhel5-1 
  6. 192.168.1.22  rhel5-2.xfcy.org     rhel5-2 

·    /etc/sysconfig/network

这个文件用于为所有网络接口设置路由和主机信息。
 
  1. [root@rhel6 ~]# cat /etc/sysconfig/network 
  2. NETWORKING=yes 
  3. HOSTNAME=rhel6.xfcy.org 
  4.  
  5. [root@rhel6 ~]# hostname 
  6. rhel6.xfcy.org 

·    /etc/sysconfig/network-script/ifcfg-<interface-name>

每一个网络接口,都有一个与之对应用的配置脚本,这些脚本文件为相应的网络接口设置指定的配置信息。
 
  1. [root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
  2. # Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) 
  3. DEVICE=eth0 
  4. TYPE=Ethernet 
  5. ONBOOT=yes                   #系统启动时是否激活设备 
  6. NM_CONTROLLED=yes               #是否被NetworkManager的服务控制 
  7. DEFROUTE=yes                    #是否把这个eth设置为默认路由 
  8. BOOTPROTO=none                  #none | dhcp | static 
  9. HWADDR=00:0C:29:BF:45:80  #硬件地址(一般与下面的MACADD相同)
  10. #MACADDR=60:EB:69:FC:4D:98 #MAC地址(如要修改网卡MAC地址必须修改该选项)
  11. IPADDR=192.168.1.119 
  12. NETWORK=255.255.255.0 
  13. GATEWAY=192.168.1.1 
  14. #IPADDR2=192.168.2.119 
  15. #NETWORK=255.255.255.0 
  16. DNS1=8.8.8.8 
  17. DNS2=8.8.4.4 
  18. PEERDNS=yes                     #是否生效DNS配置信息(将自动修改/etc/resolv.conf中nameserver的值,设为no则DNS由/etc/resolv.conf中配置的值来控制 ) 
  19. USERCTL=yes                  #允许非 root 用户控制这个设备 
  20. MASTER=bond0                    #bond0是以太网卡连接到的通道绑定接口的名称,这个指令与 SLAVE 指令配合使用。 
  21. SLAVE=<yes|no>                  #此设备是否可以由 MASTER 指令中配置的通道绑定接口进行控制 

·    /etc/resolv.conf

这个文件用于设置  DNS   IP  地址和搜索域,除非另行配置,否则网络初始化脚本总是使用这个文档中的配置信息 
 
  1. [root@rhel6 ~]# cat /etc/resolv.conf 
  2. search xfcy.org 
  3. nameserver 8.8.8.8              #RHEL6中重启后则消失 
  4. nameserver 8.8.4.4 
==============================================================================================
==============================================================================================

·    客户端通过DHCP自动获取IP地址

 
 
  1. [root@rhel5 ~]# dhclient eth0 
  2. Internet Systems Consortium DHCP Client V3.0.5-RedHat 
  3. Copyright 2004-2006 Internet Systems Consortium. 
  4. All rights reserved. 
  5. For info, please visit http://www.isc.org/sw/dhcp/ 
  6.  
  7. Listening on LPF/eth0/00:0c:29:db:14:10 
  8. Sending on   LPF/eth0/00:0c:29:db:14:10 
  9. Sending on   Socket/fallback 
  10. DHCPOFFER from 192.168.1.119 
  11. DHCPREQUEST on eth0 to 255.255.255.255 port 67 
  12. DHCPACK from 192.168.1.119 
  13. bound to 192.168.1.90 -- renewal in 9863 seconds. 
  14.  
  15. [root@rhel6 ~]# tail -f /var/log/messages 
  16. Nov 20 14:03:55 rhel6 dhcpd: DHCPREQUEST for 192.168.1.90 from 00:0c:29:db:14:10 via eth0 
  17. Nov 20 14:03:55 rhel6 dhcpd: DHCPACK on 192.168.1.90 to 00:0c:29:db:14:10 via eth0 

·    路由配置

 
 
  1. [root@rhel6 ~]# route 
  2. Kernel IP routing table 
  3. Destination     Gateway         Genmask         Flags Metric Ref    Use Iface 
  4. 192.168.1.0     *               255.255.255.0   U     1      0        0 eth0 
  5.  
  6. [root@rhel6 ~]# route add default gw 192.168.1.1 
  7. [root@rhel6 ~]# route add -net 192.168.2.0/24 gw 192.168.1.1 
  8. [root@rhel6 ~]# route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.1.1     
  9. [root@rhel6 ~]# route add -net 192.168.4.0/24 dev eth0  
  10. [root@rhel6 ~]# route add -host 192.168.5.90 dev eth0 
  11. [root@rhel6 ~]# route -n 
  12. Kernel IP routing table 
  13. Destination     Gateway         Genmask         Flags Metric Ref    Use Iface 
  14. 192.168.5.90    0.0.0.0         255.255.255.255 UH    0      0        0 eth0 
  15. 192.168.4.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0 
  16. 192.168.3.0     192.168.1.1     255.255.255.0   UG    0      0        0 eth0 
  17. 192.168.2.0     192.168.1.1     255.255.255.0   UG    0      0        0 eth0 
  18. 192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0 
  19. 0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0 
  20. [root@rhel6 ~]# route del -net 192.168.2.0/24 gw 192.168.1.1 
  21. [root@rhel6 ~]# route -n 
  22. Kernel IP routing table 
  23. Destination     Gateway         Genmask         Flags Metric Ref    Use Iface 
  24. 192.168.5.90    0.0.0.0         255.255.255.255 UH    0      0        0 eth0 
  25. 192.168.4.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0 
  26. 192.168.3.0     192.168.1.1     255.255.255.0   UG    0      0        0 eth0 
  27. 192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0 
  28. 0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0 
  29. [root@rhel6 ~]# route 
  30. Kernel IP routing table 
  31. Destination     Gateway         Genmask         Flags Metric Ref    Use Iface 
  32. 192.168.5.90    *               255.255.255.255 UH    0      0        0 eth0 
  33. 192.168.4.0     *               255.255.255.0   U     0      0        0 eth0 
  34. 192.168.3.0     192.168.1.1     255.255.255.0   UG    0      0        0 eth0 
  35. 192.168.1.0     *               255.255.255.0   U     1      0        0 eth0 
  36. default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0 
  37.  
  38. ***************************** Flags中的标识代表意义: ***************************
  39. U (route is up)                  :该路由是启动的; 
  40. H (target is a host)                 :目标是一部主机 (IP) 而非网域; 
  41. G (use gateway)                  :需要透过外部的主机 (gateway) 来转递封包; 
  42. R (reinstate route for dynamic routing)      :使用动态路由时,恢复路由信息的旗标; 
  43. D (dynamically installed by daemon or redirect) :已经由服务或转 port 功能设定为动态路由 
  44. M (modified from routing daemon or redirect)    :路由已经被修改了; 
  45. ! (reject route)                     :这个路由将不会被接受(用来抵挡不安全的网域!) 

==============================================================================================

·    网络参数综合指令:ip

 
 
  1. # ip [option] [动作] [指令] 
  2. option :设定的参数,主要有: 
  3. -s      :显示出该装置的统计数据(statistics),例如总接受封包数等; 
  4. 动作 :亦即是可以针对哪些网络参数进行动作,包括有: 
  5. address :关于额外的 IP 协议,例如多 IP 的达成等等; 
  6. link    :关于device 的相关设定,包括 MTU, MAC 地址等等 
  7. route   :与路由有关的相关设定 
 
 
 
  1. # ip address show 
  2. # ip address [add|del] [IP] [dev device] [相关参数] 
  3. 相关参数: 
  4. broadcast   :设定广播地址,如果设定值是 + 表示让系统自动计算 
  5. label       :亦即是这个装置的别名,例如 eth0:0 就是了! 
  6. scope       :这个界面的领域,通常是这几个大类: 
  7. global  :允许来自所有来源的联机(default); 
  8. site    :仅支持 IPv6 ,仅允许本主机的联机; 
  9. link    :仅允许本装置自我联机; 
  10. host    :仅允许本主机内部的联机; 
  11.  
  12. [root@rhel6 ~]# ip add show 
  13. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN  
  14.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 
  15.     inet 127.0.0.1/8 scope host lo 
  16.     inet6 ::1/128 scope host  
  17.        valid_lft forever preferred_lft forever 
  18. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 
  19.     link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff 
  20.     inet 192.168.1.119/24 brd 192.168.1.255 scope global eth0 
  21.     inet6 fe80::20c:29ff:febf:4580/64 scope link  
  22.        valid_lft forever preferred_lft forever 
  23. [root@rhel6 ~]# ip address add 192.168.2.119/24 broadcast + dev eth0 label eth0:alias               #临时手动添加一条IP别名 
  24. [root@rhel6 ~]# ip add show 
  25. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN  
  26.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 
  27.     inet 127.0.0.1/8 scope host lo 
  28.     inet6 ::1/128 scope host  
  29.        valid_lft forever preferred_lft forever 
  30. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 
  31.     link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff 
  32.     inet 192.168.1.119/24 brd 192.168.1.255 scope global eth0 
  33.     inet 192.168.2.119/24 brd 192.168.2.255 scope global eth0:alias 
  34.     inet6 fe80::20c:29ff:febf:4580/64 scope link  
  35.        valid_lft forever preferred_lft forever 
  36.  
  37. [root@rhel6 ~]# ifconfig eth0:alias 
  38. eth0:alias Link encap:Ethernet  HWaddr 00:0C:29:BF:45:80   
  39.           inet addr:192.168.2.119  Bcast:192.168.2.255  Mask:255.255.255.0 
  40.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
  41. [root@rhel6 ~]# ip add del 192.168.2.119/24 dev eth0                                #临时手动删除一条IP别名 
 
 
 
  1. # ip [-s] link show 
  2. # ip link set [device] [动作与参数] 
  3. 动作与参数:包括有底下的这些动作: 
  4. up|down     :启动 (up) 或关闭 (down) 某个接口,其他参数使用默认的以太网 
  5. address     :修改 MAC 地址 
  6. name        :给予这个装置一个特殊的名字; 
  7. mtu         :最大传输单元 
  8. [root@rhel6 ~]# ip link show 
  9. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN  
  10.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 
  11. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 
  12.     link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff 
  13. [root@rhel6 ~]# ip -s link show eth0 
  14. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 
  15.     link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff 
  16.     RX: bytes  packets  errors  dropped overrun mcast    
  17.     1284926    15957    0       0       0       0       
  18.     TX: bytes  packets  errors  dropped carrier collsns  
  19.     5592979    11652    0       0       0       0       
  20.  
  21. [root@rhel6 ~]# ip link set eth0 down 
  22. [root@rhel6 ~]# ip link show eth0 
  23. 2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state Down qlen 1000 
  24.     link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff 
  25. [root@rhel6 ~]# ip link set eth0 up 
  26. [root@rhel6 ~]# ip link show eth0     
  27. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 
  28.     link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff 
 
 
 
  1. # ip route show 
  2. # ip route [add|del] [IP] [via gateway] [dev device] 
  3. [root@rhel6 ~]# ip route show 
  4. 192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.119  metric 1  
  5. [root@rhel6 ~]# ip route add 192.168.2.0/24 via 192.168.1.1 
  6. [root@rhel6 ~]# ip route add 192.168.3.0/24 dev eth0 
  7. [root@rhel6 ~]# ip route add default via 192.168.1.1 dev eth0 
  8. [root@rhel6 ~]# ip route show 
  9. 192.168.3.0/24 dev eth0  scope link  
  10. 192.168.2.0/24 via 192.168.1.1 dev eth0  
  11. 192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.119  metric 1  
  12. default via 192.168.1.1 dev eth0  
  13.  
  14. [root@rhel6 ~]# route -n 
  15. Kernel IP routing table 
  16. Destination     Gateway         Genmask         Flags Metric Ref    Use Iface 
  17. 192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0 
  18. 192.168.2.0     192.168.1.1     255.255.255.0   UG    0      0        0 eth0 
  19. 192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0 
  20. 0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0 
  21.  
  22.  
  23. [root@rhel6 ~]# ip route del 192.168.3.0/24 
  24. [root@rhel6 ~]# ip route del default 
  25. [root@rhel6 ~]# ip route show        
  26. 192.168.2.0/24 via 192.168.1.1 dev eth0  
  27. 192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.119  metric 1  
  28.  
  29. [root@rhel6 ~]# route -n 
  30. Kernel IP routing table 
  31. Destination     Gateway         Genmask         Flags Metric Ref    Use Iface 
  32. 192.168.2.0     192.168.1.1     255.255.255.0   UG    0      0        0 eth0 
  33. 192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0 

 



     本文转自Vnimos51CTO博客,原文链接:http://blog.51cto.com/vnimos/1064758,如需转载请自行联系原作者




相关文章
|
4月前
|
机器学习/深度学习 移动开发 测试技术
RT-DETR改进策略【模型轻量化】| 替换骨干网络为MoblieNetV2,含模型详解和完整配置步骤
RT-DETR改进策略【模型轻量化】| 替换骨干网络为MoblieNetV2,含模型详解和完整配置步骤
128 1
RT-DETR改进策略【模型轻量化】| 替换骨干网络为MoblieNetV2,含模型详解和完整配置步骤
|
7月前
|
安全 网络安全 数据安全/隐私保护
|
3月前
|
域名解析 网络协议 Linux
网络基础知识与配置
本文介绍了网络基础知识,涵盖网络概念、协议、拓扑结构及IP地址等内容。网络是由计算机设备通过通信线路连接而成的系统,用于资源共享与信息传递。文中详细解析了TCP/IP协议族(如IP、TCP、UDP)、常见应用层协议(如HTTP、FTP、SMTP、DNS)的功能与应用场景。同时,阐述了多种网络拓扑结构(总线型、星型、环型、树型、网状)的特点与优缺点。此外,还讲解了IP地址分类、子网掩码的作用,以及如何在Windows和Linux系统中配置网络接口、测试连通性(Ping、Traceroute)和查看默认网关与路由表的方法。这些内容为理解和管理计算机网络提供了全面的基础知识。
187 6
|
4月前
|
机器学习/深度学习 计算机视觉
RT-DETR改进策略【Backbone/主干网络】| 替换骨干网络为2023-CVPR LSKNet (附网络详解和完整配置步骤)
RT-DETR改进策略【Backbone/主干网络】| 替换骨干网络为2023-CVPR LSKNet (附网络详解和完整配置步骤)
118 13
RT-DETR改进策略【Backbone/主干网络】| 替换骨干网络为2023-CVPR LSKNet (附网络详解和完整配置步骤)
|
4月前
|
机器学习/深度学习 编解码 数据可视化
RT-DETR改进策略【Backbone/主干网络】| 替换骨干网络为2023-CVPR ConvNeXt V2 (附网络详解和完整配置步骤)
RT-DETR改进策略【Backbone/主干网络】| 替换骨干网络为2023-CVPR ConvNeXt V2 (附网络详解和完整配置步骤)
225 11
RT-DETR改进策略【Backbone/主干网络】| 替换骨干网络为2023-CVPR ConvNeXt V2 (附网络详解和完整配置步骤)
|
3月前
|
监控 安全 网络协议
Hyper V上网实战:多虚拟机网络环境配置
在Hyper-V环境中配置多虚拟机网络以实现上网功能,需完成以下步骤:1. 确认Hyper-V安装与物理网络连接正常;2. 配置虚拟交换机(外部、内部或专用)以支持不同网络需求;3. 设置虚拟机网络适配器并关联对应虚拟交换机;4. 验证虚拟机网络连接状态;5. 根据场景需求优化多虚拟机网络环境。此外,还需注意网络隔离、性能监控及数据备份等事项,确保网络安全稳定运行。
|
3月前
|
安全 网络协议 网络安全
当虚拟机出现网络连接问题时,应该先检查Hyper-V的网卡连接配置
当虚拟机出现网络连接问题时,应首先检查Hyper-V的网卡配置。具体步骤包括:确认虚拟机运行状态、检查虚拟交换机类型和物理网卡连接、确保虚拟机网络适配器正确连接到虚拟交换机,并验证网络配置(IP地址等)。常见问题如虚拟交换机配置错误、网络适配器未连接或防火墙阻止连接,可通过重新配置或调整设置解决。必要时重启虚拟机和宿主机,查看事件日志或联系技术支持以进一步排查问题。
|
4月前
|
机器学习/深度学习 移动开发 测试技术
YOLOv11改进策略【模型轻量化】| 替换骨干网络为MoblieNetV2,含模型详解和完整配置步骤
YOLOv11改进策略【模型轻量化】| 替换骨干网络为MoblieNetV2,含模型详解和完整配置步骤
188 13
YOLOv11改进策略【模型轻量化】| 替换骨干网络为MoblieNetV2,含模型详解和完整配置步骤
|
3月前
|
虚拟化 网络虚拟化 Windows
导入虚拟机到Hyper-V环境时,理解并配置网络适配器设置是确保网络通信的关键
在Hyper-V环境中,正确配置虚拟机的网络适配器是确保其网络通信的关键。需先启用Hyper-V功能并创建虚拟交换机。接着,在Hyper-V管理器中选择目标虚拟机,添加或配置网络适配器,选择合适的虚拟交换机(外部、内部或私有),并根据需求配置VLAN、MAC地址等选项。最后,启动虚拟机并验证网络连接,确保其能正常访问外部网络、与主机及其他虚拟机通信。常见问题包括无法访问外部网络或获取IP地址,需检查虚拟交换机和适配器设置。
|
5月前
|
安全 网络协议 网络安全
【Azure APIM】APIM服务配置网络之后出现3443端口不通,Management Endpoint不健康状态
如果没有关联的网络安全组,则阻止所有网络流量通过子网和网络接口。
129 30

热门文章

最新文章