####linux下的网络配置###

    1.什么是IP
         internet protocol ADDRESS ###网络进程地址
     ipv4  internet protocol version 4

    1.2x32
      ip是由32个01组成
      11111110.11111110.11111110.11111110 = 254.254.254.254
      
     2.子网掩码
        用来划分网络区域
        子网掩码非0的位对应的ip上的数字表示这个ip的网络位
        子网掩码0位对应的数字时ip的主机位
        网络位表示网络区域
        主即位表示网络区域内某台主机

    3.ip通信判定
      网络位一致,主机位不一致的2个IP可以直接通讯
      172.25.254.1/24   24=255.255.255.0
      172.25.254.2/24   
      172.25.0.1/16

     4.网络设定工具
     ping      ##检测网络是否通畅
    ifconfig    ##查看或设定网络接口
    ifconfig    ##查看
    ifconfig device ip/24 ##设定
    ifconfig device down  ##关闭
    ifconfig device up    ##开启

     ip  add  ##检测网络接口
     ip  addr show ##检测
     ip  addr add ip/24 dev device  ##设定
     
     注意:device的名字是一个物理事实,看到什么名字只能用什么名字“


     
#####5.图形方式设定IP
    1.nm-connection-editor
     systemctl stop NetworkManager
     systenctl restart network
     systemctl start NetworkManager

    2.nmtui

###6.命令方式设定网络
  nmcli       ###NetworkManger必须开启
  nmcli  device connect eth0 ##启用eth0网卡
  nmcli  device disconnect etho  ##关闭eth0网卡
  nmcli  device status eth0 ##查看网卡接口信息

  nmcli connection show
  nmcli connection down westos
  nmcli connection up westos
  nmcli connection delete westos
  nmcli connection add type ethernet con-name westos ifname eth0  ip4  172.25.254.0/24

  nmcli connection modify westos  ipv4.method auto
  nmcli connection modify westos  ipv4.method mamual
  nmcli connection modify westos  ipv4.addresses 172.25.254.200/24

   ####7.管理网络配置文件###
   网络配置目录
  /etc/sysconfg/network-scripts/
  网络配置文件的命名规则
 
  ifcfg-xxxx   
  DEVICE=xxx    ##设备名称
  BOOTPROTO=dhcp|static|none  ##设备工作方式
  ONBOOT=yes     ##网络服务开启时自动激活网卡
  IPADDR=       ##IP地址
  PREFIX=24     ##子网掩马
  NETMARK=255.255.255.0  ##子网掩马
  NAME=             ##接口名称
 
  示例:静态网络设定
  vim /etc/sysconfig/network-scipts/ifcfg-eth0
  DEVICE=eth0
  ONBOOT=yes
  IDADDR=172.25.254.166
  PREFIX=24
  BOOTPROTO=none
  NAME=aaa

  systemctl restart network


 
  ##一块网卡上配置多个IP##
 
  vim /etc/sysconfig/network-scipts/ifcfg-eth0
  DEVICE=eth0
  ONBOOT=yes
  IDADDR0=172.25.254.166
  PREFIX=24
  BOOTPROTO=none
  NAME=westos
  IDADDR1=172.25.254.155
  PREFIX=24
 
  systemctl restart network
  ip addr show eth0


####8.lo回环接口####
  回环接口---人的神经---127.0.0.1---localhost
      
  ###9.网关####

  1.把真实主机变成路由器
  systemctl stop libvirtd
  systemctl restart firewalld
  systemctl start libvirtd
 
  firewall-cmd --list
  firewall-cmd --permanent --add-masquerade
  firewall-cmd --reload
  firewall-cmd --list-all


 
  public (active)
    target: default
  icmp-block-inversion: no
  interfaces: br0 enp0s25 wlp3s0
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  masquerade: yes   <<<地址伪装功能开启,真实主机变成路由器>>>
  forward-ports:
  sourceports:
  icmp-blocks:
  rich rules:

 2.设定虚拟机网管
 
  vim /etc/sysconfig/network   ##全局网关,针对于所有没有设定网管的                                   网卡生效
  GATEWAY=172.25.254.250

  vim /etc/sysconfig/network-scripts/ifcfg-eth0
   GATEWAY0=172.25.254.250    ###当网卡中有多个IP时,指定对于哪个IP生效
   GATEWAY=172.25.254.250   ##当网卡中设定的IP只有一小时


 route -n    ###查看网关

       

  Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  0.0.0.0        "172.25.254.250"  0.0.0.0         UG    1024   0        0 eth0
  172.25.0.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0
  172.25.254.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0


 
 
###10.dns##
domain name server ==域名解析服务  ##解析就是把域名变成IP

vim /etc/hosts   ##本地解析文件
ip                    域名  
220.181.111.188  www.baidu.com  

vim /etc/resolv.conf       ##dns的指向文件
nameserver 114.114.114.114   ##当需要某个域名的Ip地址去问114.。。

vim /etc/sysconfig/network-scripts/ifconfg-xxxx
DNS1=114.114.114.114


注意:
      当网络工作模式为dhcp时
      系统会自动获得IP网关dns
      那么/etc/resolv.conf会被获得道德信息修改
      如果不需要获得dns信息
      在网卡配置文件中加入
       PREEDNS=no

###11.设定解析的优先级
系统默认:
  /etc/hosts  >  /etc/resolv.conf
 
 vim /etc/nsswitch.conf
39 hosts:  files dns    ##/etc/hosts优先

vim /etc/nsswitch.conf
39 hosts:  dns files    ##/etc/resolv.conf dns 指向优先

猜你喜欢

转载自blog.csdn.net/tt2048/article/details/81228307
今日推荐