The Linux network configuration and bond introduced

             The Linux network configuration and bond introduced

A, Linux system, basic network configuration overview

Linux system after installation is complete, our primary task is to configure the network systems, network configuration here would include: How IP network configuration, gateway routing configuration, DNS host configuration, configuration, and server hostname if installed when a network port we also need to configure multiple IP network port used even in the form of binding (bond) to meet our needs, and so on.

Linux system, according to the form of different configuration, generally divided into two forms: permanent and temporary network configuration of the network configuration. Temporary network configuration means: the use of network information ifconfig commands to configure, it will take effect immediately, but after the restart network services and systems, the configuration will fail. Permanent network configuration means: by modifying the system after the relevant network configuration files, and save, restart the network services will be permanent.

Second, a temporary network configuration

Check the configuration of the current network] to use [ifconfig, if you want to display all the Ethernet port, regardless of whether it is active ports, use [] to ifconfig -a. As shown below:

 

Network configuration information display system of the current port, wherein the Ethernet network interface eth0, LO indicates the local loopback interface. Here are temporarily set the network configuration using ifconfig, note that these changes will not be saved to the system's network configuration files will be restored to an unmodified state before the restart network services.

  1. Temporarily modify IP

Temporarily modify the IP network interface name using ifconfig [ip], such as ifconfig eth0 10.82.25.90

 

  We can see we have temporarily changed to IP 10.82.25.90

  1. Modify Gateway

View native Linux system routing information, using the [route -n], option [n] represented digitally displayed, you can not add options direct route, increase the use of [gateway route add default gw 10.82.25.2 dev network port name] the deletion will add to del changed

 

  1. Modify DNS

DNS in /etc/resolv.conf] [path system, modify the DNS directly modify the configuration file, save takes effect, we directly use vi to edit the file

 

如图我们直接使用VI将DNS修改为10.82.1.6,保存退出即可。

经过上面的IP、网关、DNS修改后,我们验证下修改后能否访问在一个局域网的机器,ping下:

 

Ping的通,说明我们的设置和修改是正确的。

重启网络服务以上配置失效,重启命令:service network restart

三、永久的网路配置

     所谓永久指:进入系统网络相关的配置文件直接修改。

  1. 修改IP

Linux系统下的IP配置在【/etc/sysconfig/network-scripts /ifcfg-eth0】路径下,如果有多个网口,则会有eth0、eth1…等

 

上图我们修改的是eth0网口的IP,其中文档中的一些参数:DEVICE表示网口名称,ONBOOT表示是否开机激活此网口(yes:激活,no:不激活),IPADDR表示设置IP,BOOTPROTO表示获取IP的形式(static:获取静态IP,dhcp获取动态IP),做相应的修改即可,保存退出vi后,重启网关服务永久生效。

  1. 修改网关地址

系统保存网关在【/etc/sysconfig/network】路径下,同样使用vi进去修改

 

其中NETWORKING表示是否使用网络(yes表示使用,no表示不使用),HOSTNAME表示主机名称,GATEWAY表示网关。

  1. 修改DNS

DNS保存在【/etc/resolv.conf】路径下,前面已说明。

这样就全部配置完成,此时需要重启网络服务:【service network restart】,重启完成后,ping下在同一局域网的IP,ping的通则说明配置完成,可以上网啦!

  应该注意到linux系统下IP、网关和DNS分别在不同的路径文件中,这是由于linux文件系统早已做了规范,有兴趣可以去百度学习下linux系统的文件系统构成以及哪些路径存储什么文件,这里不做介绍!

上面两种方式介绍完了,一个是临时修改,用于用户做些临时任务需要的网络环境,第二种是直接修改配置文件,做永久设定该linux系统的网络配置,个 人建议如果不经常改变网络环境,修改相关网络配置文件设置网络就行了。其实除了上面介绍的两种,还有一种方式也可以,就是用户直接登陆linux主机系统,在操作系统GUI页面设置,就如windows系统设置IP一样,但linux是多人多任务的系统,用户实际上都是通过SSH远程客户端工具(secureCRT、Xshell等)来远程工作的,故此方法不做介绍!

、网口绑定(bond)简介

    此部分内容,只做简单介绍,大部分理论学习来自网络大咖,但这个bond技术还是有必要认识下的。

    网卡bond就是通过把多个网卡绑定为一个逻辑网卡,实现网口冗余、负载均衡,增加服务器 的可靠性、稳定性,提高网络带宽。

Bond的7种模式:

  1. mode=0

负载均衡模式,和交换机的端口聚合强制不协商的方式配合

         2. mode=1

表示主备模式,即主用网口和备用网口,主用故障后,备用开始工作

        3. mode=2

表示XOR Hash负载分担模式,和交换机的端口聚合强制不协商的方式配合

       4. mode=3

表示broadcast广播模式

       5. mode=4

表示支持802.3ad协议,和交换机的聚合LACP方式配合

      6. mode=5

表示根据每个slave的负载情况选择slave进行发送

      7. mode=6

表示负载均衡模式,只是她不依赖于交换机的汇聚

常用的mode有三种:

Mode=0:平衡负载均衡模式,系统会将当前的所有网络流量平均分配到每个网卡上,如eth0、eth1…

Mode=1:主备冗余模式,如果其中一个网卡出问题,另一个继续工作,保证网络的连续

Mode=6: 平衡负载均衡模式,与mode0不同的是,系统会将网络流量先负载到eth0,负载满后,多的流量再负载到eth1,以此顺延。

Bond模式网口绑定设置:

   还不怎么会,配置有点麻烦,后面有时间去研究下,这里暂不介绍。

需要的环境:

   一套装有linux系统的服务器;2个物理网口:eth0、eth1;服务器IP

Guess you like

Origin www.cnblogs.com/tdp0108/p/12407683.html