Linux入门学习(十)

管理网络

  • ip基础知识
    • ipv4 2进制32位—–10进制
      • 172.25.0.10/255.255.255.0
      • 172.25.0.10:ip地址
      • 255.255.255.0:子网掩码
      • 子网掩码255位对应的ip位为网络位
      • 子网掩码0对应的ip位为主机位
  • 配置ip

    • 图形化
      • 图形界面 nm-connection-editor
      • 文本化图形 nmtui
    • 命令

      • ifconfig 网卡 ip netmask :临时设定
      命令 备注
      nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes 添加dhcp网络
      nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24 添加静态网络
      nmcli connection delete westos 删除westos链接
      nmcli connection show 显示所有网络链接
      nmcli connection down westos 关闭指定链接
      nmcli connection up westos 开启指定链接
      nmcli connection modify “westos” ipv4.addresses newip/24 改变wetos的ip
      nmcli connection modify “westos” ipv4.method (auto manual)`
      nmcli device connect eth0 开启设备
      nmcli device disconnect eth0 关闭设备
      nmcli device show 显示设备信息
      nmcli device status 显示设备状态
    • 文件

      • dhcp :动态获取

        • vim /etc/sysconfig/network-scripts/ifcfg-eth0

          文件行 备注
          DEVICE=eth0 接口使用设备
          BOOTPROTO=dhcp 网卡工作模式
          ONBOOT=yes 网络服务开启时自动激活
          NAME=eth0 网络接口名称
        • systemctl restart network
      • static|none :静态网络

        • vim /etc/sysconfig/network-scripts/ifcfg-eth0

          文件行 备注
          DEVICE=eth0 设备
          BOOTPROTO=static none
          ONBOOT=yes 开启网络服务激活设备
          NAME=eth0 网络接口名称
          IPADDR=172.25.0.100 IP
          NETMASK=255.255.255.0 PREFIX=24
  • gateway 网关

    • 路由器
      • 主要功能是用来作nat的
      • dnat :目的地地址转换
      • snat :源地址转换
    • 网关:路由器上和自己处在同一个网段的那个ip
    • 设定网关
      • systemctl stop NetwrokManager
      • vim /etc/sysconfig/network :全局网关
        • GATEWAY=网关ip
      • vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件:网卡接口网关
        • GATEWAY=网关ip
      • systemctl restart netwrok
    • route -n :查询网关
    • 这里写图片描述
  • dns
    • dns:dns是一台服务器,这太服务器提供了回答客户主机名和ip对应关系的功能
    • 设定dns
      • vim /etc/resolv.conf
        • nameserver dns服务器ip
      • vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件
        • DNS1=dns服务器ip
    • 本地解析文件
      • vim /etc/hosts
        • ip 主机名称
      • 本地解析文件和dns读取的优先级调整
        • /etc/nsswitch.conf
        • 这里写图片描述
    • dhcp服务的配置
      • yum install -y dhcp:安装dhcp软件包
      • 查看dhcpd服务配置文件
        • 这里写图片描述
      • 拷贝配置文件
        • 这里写图片描述
      • 编辑配置文件
        • vim /etc/dhcp/dhcpd.conf
        • 这里写图片描述
      • systemctl start dhcpd
      • systemctl status dhcpd
发布了31 篇原创文章 · 获赞 3 · 访问量 4543

猜你喜欢

转载自blog.csdn.net/Lengwenin/article/details/79936194
今日推荐