十Linux 下的网络配置

###########Linux下的网络配置###########
1,什么是IP ADDRESS
    ipv4 internet protocol ADSRESS##网络进程地址
    1,ip由32位二进制数字组成,每8位一组
2子网掩码:24位数字啦,一般前面为1,用于确定网络位
3ip通信判定:网络号一致,主机位不一样
                     172.25.254.1/24该区域第一个主机
                     ping ip 查看是否可以通信;为了通信可以临时更改ip(nm-connection-editor)
4网络设定工具
        ping     检测网络是否畅通


        ifconfig 查看或设定网络接口


        ifconfig device ip/24  设定
        ip addr  检测这项网络接口
        ip addr show 检测


        ip addr add ip/24 dev device  设定接口ip
             补充:查看日志谁给的ip,当关了dhcp服务,无ip
        永久设定
5图形方式设定ip
          1    nm-connection-editor
        systemctl stop     NetworkManager
        systemctl restart network
        systemctl start NetworkManager


          2,nmtui


6命令方式设定网络
        nmcli device connect eth0    启用eth0网卡
        nmcli device disconnect eth0    关闭eth0网卡
        nmcli device show eth0        查看网卡信息

扫描二维码关注公众号,回复: 2556960 查看本文章

       
        nmcli device status eth0        查看网卡服务接口信息

      
        
        nmcli connection show        查看接口信息

      
        nmcli connection down westos    关闭westos接口
        nmcli connection up westos    开启westos接口
        nmcli conection delete westos    删除
       nmcli connection add type ethernet con-name westos ifname eth0 ipv4 172.25.254.234/24     添加westos接口

       
        nmcli connection modify westos ipv4.method auto    添加动态接口
        nmcli connection modify westos ipv4method manual  添加静态接口
        nmcli connection modify westos ipv4.addresses 172.25.254.200/24
7管理网络配置文件
 网络配置目录/etc/sysconfig/network-scripts/
 网络配置文件的命名规则:ifcfg=xxx
            DEVICE=XXX            设备名称
            BOOTPROTO=decp|static|none    设备工作方式
            ONBOOT=yes            网络服务开启时自动激活网卡
            IPADDR=XXX            IP
            PREFIX=24            子网掩码
            NETMASK=255.255.255.0        子网掩码
  示例:
    静态网络设定文件
    vim /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    ONBOOT=yes
    IPADDR=172.25.254.200
    NETMASK=255.255.255.0
    BOOTPROTO=none
    NAME=westos
        systemctl restart network
    一块网卡配置多个ip
    vim /etc/sysconfig/network-scripts/ifcfg-eth0
        DEVICE=eth0
        ONBOOT=yes
        IPADDR0=172.25.254.200
        NETMASK=255.255.255.0
        BOOTPROTO=none
        NAME=westos
    IPADDR1=172.25.0.100
    PREFIX1=24
        systemctl restart network
       
8了解 回环接口
9网关:
    1把真实主机变成路由器
    systemctl stop libvirtd
    systemctl reestart firewalld
    systemctl start libvirtd
    
    firewall-cmd --list
    firewall-cmd --permanent --add-masquerade

   
    firewall-cmd --reload

   
    firewall-cmd --list-all

伪装成功则显示

    2设定虚拟机网关
    vim /etc/sysconfig/network  全局网关,针对所有没有设定网关的网卡生效
    GETEWAY=172.25.254.250
    vim /etc/sysconfig/network-scripts/ifcfg-eth0 GATEWAY=172.25.254.250

10dns
    domain name server == 域名解析服务 即把域名变ip
    vim /etc/hosts 本地解析文件
    格式:ip 域名  eg:220.181.111.188  www.baidu.com
    vim /etc/resolv.conf  dns的指向文件
    nameserver 114.114.114.114 当需要某个域名去问114
    注意:当网络工作模式为dhcp时,则/etc/resolv.conf会被获得的信息修改
    如果网络不需要dns信息,在网卡配置文件中加PREEDNS=no
11设定解析的优先级
系统默认:本地解析优先 /etc/hosts > /etc/resolv.conf
          vim /etc/nsswitch.conf   39 hosts: files dns 则/etc/hosts优先
12dhcp:动态分配ip
   安装dhcp服务在一台主机
  yum install dhcp -y
  cd /etc/dhcp/
  vim dhcpd.conf
  修改相关地方,并配置网络池
  systemctl rstart dhcpd
测试:在虚拟机端解除静态网络的配置
      配置/etc/sysconfig/network-scripts/ifcfg-eth0

10dns
    domain name server == 域名解析服务 即把域名变ip
    vim /etc/hosts 本地解析文件
    格式:ip 域名  eg:220.181.111.188  www.baidu.com
    vim /etc/resolv.conf  dns的指向文件
    nameserver 114.114.114.114 当需要某个域名去问114
    注意:当网络工作模式为dhcp时,则/etc/resolv.conf会被获得的信息修改
    如果网络不需要dns信息,在网卡配置文件中加PREEDNS=no
11设定解析的优先级
系统默认:本地解析优先 /etc/hosts > /etc/resolv.conf
          vim /etc/nsswitch.conf   39 hosts: files dns 则/etc/hosts优先
12dhcp:动态分配ip
   安装dhcp服务在一台主机
  yum install dhcp -y
  cd /etc/dhcp/
  vim dhcpd.conf
  修改相关地方(删除35以后,改时区,删除27,28,),加入子网,并配置网络池
  systemctl rstart dhcpd
测试:在虚拟机端解除静态网络的配置
           配置/etc/sysconfig/network-scripts/ifcfg-eth0

           ONBOOTPROTO=yes

10dns
    domain name server == 域名解析服务 即把域名变ip
    vim /etc/hosts 本地解析文件
    格式:ip 域名  eg:220.181.111.188  www.baidu.com
    vim /etc/resolv.conf  dns的指向文件
    nameserver 114.114.114.114 当需要某个域名去问114
    注意:当网络工作模式为dhcp时,则/etc/resolv.conf会被获得的信息修改
    如果网络不需要dns信息,在网卡配置文件中加PREEDNS=no
11设定解析的优先级
系统默认:本地解析优先 /etc/hosts > /etc/resolv.conf
          vim /etc/nsswitch.conf   39 hosts: files dns 则/etc/hosts优先
12dhcp:动态分配ip
   安装dhcp服务在一台主机
  yum install dhcp -y
  cd /etc/dhcp/
  vim dhcpd.conf
  修改相关地方,并配置网络池
  systemctl rstart dhcpd


测试:在虚拟机端解除静态网络的配置
      配置/etc/sysconfig/network-scripts/ifcfg-eth0

      ONBOOTPROTO=dhcp

       ONBOOTPROTO=yes

       DEVICE=eth0

      重启dhcp,关闭火墙 并查看ip

     

          

猜你喜欢

转载自blog.csdn.net/qq_42784898/article/details/81329960
今日推荐