Linux下配置静态ip以及网络管理

Linux上网络相关的守护进程

摘录自How exactly are NetworkManager, networkd, netplan, ifupdown2, and iproute2 interacting?
有一位答主梳理了网络管理的一些工具:

  1. interfaces configuration files & ifup & ifdown ,老三件

    The /etc/network/interfaces network configuration file seems to be fairly old, but is still used by ifup, ifdown and ifquery.

  2. 经典命令 ifconfig
    来自 net-tools:A collection of programs that form the base set of the NET-3 networking distribution for the Linux operating system。 参考wiki,如今相当部分被标记为obsolete。其替代套件为Iproute2
    programobsolete by
    arpip neigh
    ifconfigip addr
    ifmaddrip maddr
    iftunnelip tunnel
    routeip route
    nameififrename
    mii-toolethtool
  3. ipifup/ifdown 的关系
    暂略,似乎我的服务器没有ifup
  4. NetworkManager(2004)
    参考Manual NetworkManger.conf(5)
    ...
    Plugins
          ifupdown
          This plugin is used on the Debian and Ubuntu distributions, and reads Ethernet and Wi-Fi connections from /etc/network/interfaces.
    ...
    
    此时ifup/ifdown已经成为了一个相对低层的配置方案了。
  5. systemd-networkd (2010)
    systemd-networkd(8) 属于 systemd的一部分,感觉像一种“釜底抽薪”式的终极方案。(毕竟systemd已经代替init成为linux下的System daemon)

    systemd-networkd will manage network addresses and routes for any link for which it finds a .network file with an appropriate [Match] section, see systemd.network(5). For those links, it will flush existing network addresses and routes when bringing up the device. Any links not matched by one of the .network files will be ignored.

配置静态IP

编辑本机配置实现静态IP

在前面的背景下,配置静态IP的方法就比较明确了。使用network manager,开启ifupdown插件,编辑/etc/network/interface文件

  1. 首先检查NetworkManger是否被使用
    systemctl | grep -i networkmanager
    
  2. 开启ifupdown
    cat /etc/NetworkManager/NetworkManager.conf 
    >>>
    [main]
    plugins=ifupdown,keyfile
    
  3. 编辑/etc/network/interface文件
    auto eth0 # 自动启动
    iface eth0 inet static
    	address 192.168.0.1
    	netmask 255.255.255.0
    

注意,本部分并未实际测试,ifdown/ifup在个人服务器上已经没有了,酌情取用。可以尝试networkmanager自身的方案。

利用DHCP协议实现静态IP

DHCP 服务可以配置静态IP分配(静态 DHCP 条目),将静态IP地址与目标设备的MAC地址绑定。这里需要对网关的访问权限。

其他问题

摘抄供内网使用的网段

RFC 1918 nameIP address rangeNumber of addresses Largest CIDR block (subnet mask)Host ID sizeMask bits Classful description[Note 1]
24-bit block10.0.0.0 – 10.255.255.2551677721610.0.0.0/8 (255.0.0.0)24 bits8 bitssingle class A network
20-bit block172.16.0.0 – 172.31.255.2551048576172.16.0.0/12 (255.240.0.0)20 bits12 bits16 contiguous class B networks
16-bit block192.168.0.0 – 192.168.255.25565536192.168.0.0/16 (255.255.0.0)16 bits16 bits256 contiguous class C networks

DNS配置resolve.conf被NetworkManger覆盖

  • 使用 man interface 发现 /etc/network/interface 并不支持 dns 设置
  • 实际上 NetworkManager 的配置文件为 /etc/NetworkManager/NetworkManager.conf ,使用 man networkmanager.conf 可以找到关于dns的配置方法
  • 简单起见,设置了dns mode为none,自定义 /etc/resolv.conf 文件,此时该文件不会被NetworkManger 覆盖
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值