linux网络配置

 1. 什么是IP ADDRESS

     internet   protocol   ADDRESS                        ##网络进程地址
     ipv4    internet protocol version 4
     1.2进制X32
     ip是由32个01组成
     11111110.111111110.111111110.111111110 = 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                                    #检查网络是否通畅
   inconfig                              #查看或设定网络接口

 

   ifconfig device ip/24           #设定

 

   ifconfig device down / up   #关闭或开启

   ip addr                                #检测或 网络接口

 


   ip addr show                      #检测

 


   ip addr add ip/24 dev device   #设定

 

   注意:device 的名字是一个物理事实,看到什么名字用什么名字

###5 图形方式设定IP#
1 nm-connection -editor

 


systemctl stop NetworkManager
systemctl restart network
systemctl restart NetworkManager

 

2nmtui


###6 命令方式设定网络
nmcli                                         ##NetworkManager必须开启
nmcli device connect eth0        #启用eth0网卡

 


nmcli device  disconnect etho  #关闭eth0网卡

 

 


nmcli  device show eth0           #查看网卡信息

 


nucli  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.100/24

 

 


nmcli connection modify westos  ipv4.method auto

 


nmcli connection modify westos  ipv4.method manual
nmcli connection modify westos  ipv4.addresses 172.25.254.200/24

 

##管理网络配置文件
网络配置目录
/etc/sysconfig/network -scripts/
网络配置文件的命名规则
ifcfg-xxxx
DEVICE=xxx                              #设备名称
BOOTRTO=dhcp|static|none    #设备工作方式
ONBOOT=yes                          #网络服务开启时自动激活网卡
IPADDR=                                 #IP地址
PREFIX=24                             ##子网掩码
NETMASK=255.255.255.0
NAME=                                   #接口名称

示例
静态网络设定文件
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=xxx                              #设备名称
BOOTRTO=dhcp|static|none     #设备工作方式
ONBOOT=yes                            #网络服务开启时自动激活网卡
IPADDR=                                    #IP地址
PREFIX=24                                 ##子网掩码
NETMASK=255.255.255.0
NAME=                                       #接口名称

 

 

 ## 回环接口
 回环接口---人的神经---127.0.0.1---localhost


一块网卡配置多个IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=xxx                             #设备名称
BOOTRTO=dhcp|static|none    #设备工作方式
ONBOOT=yes                          #网络服务开启时自动激活网卡
IPADDR1=                                #IP地址
PREFIX1=24                             ##子网言马
NETMASK=255.255.255.0
NAME=                                    #接口名称

 

#将真机伪装成路由器##


systemctl stop libvirtd
systemctl restart firewalld
systemctl start libvirtd

firewall-cmd --list
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload
firewall-cmd --list-all

 

2设定虚拟机的网关

vim /etc/sysconfig/network        #全局网关,针对没有设定网关的网卡生效
GATEWAY=172.25.254.250

 

vim   /etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY0=172..25.254.250    #设定ip有多个时,指定那个设定
GATEWAT=172.25.254.250       #网卡设定的ip只有一个

 

 

##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.114.114.114

 

 

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

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

###设定解析的优先级
系统默认:
/etc/hosts > /etc/resolv.confvim /etc/nsswitch.conf39 hosts: files dns                 ##/etc/hosts 优先

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

 

posted @ 2018-07-31 19:49  正义的朋友  阅读(189)  评论(0编辑  收藏  举报