一次关于误操作dhclient-script故障记录

一次关于误操作dhclient-script故障记录

A dhclient-script failure record for an incorrect operation

起因

Causes

因有一个服务于aws的域名解析失败,导致业务无法正常发布. 国内解析aws的域名失败,国外正常. 此时有两个解决方法:

  1. 配置hosts
  2. 修改/etc/resolv.conf 修改hosts可临时解决问题,但如果aws换了指向,还需要再做修改。 所以使用第二种方法。 但当修改完 /etc/resolv.conf后,执行命令service network restart,会发现/etc/resolv.conf被重置,使修改失效。 经查是因为/usr/sbin/dhclient-script所致。

因一时疏忽直接执行了:

代码语言:javascript
复制
mv /usr/sbin/dhclient-script /usr/sbin/dhclient-scriptbak
service network restart

执行完后一脸懵逼,ec2成砖头了,链接断开,再也无法链接.

Due to a domain name resolution failure for AWS, the business cannot be published normally.

Domestic resolution of AWS domain failed, foreign normal.

There are two solutions:

  1. The configuration of hosts
  2. Modify the/etc/resolv. Conf

Modifying Hosts can solve the problem temporarily, but you will need to make further changes if AWS is directed elsewhere.

So use the second method.

But when modifying the/etc/resolv. Conf, execute the command service network restart, will find that the/etc/resolv. Conf reset, disable modification.

/usr/sbin/dhclient-script = /usr/sbin/dhclient-script = /usr/sbin/dhclient-script

To execute directly out of an oversight:

代码语言:javascript
复制
mv /usr/sbin/dhclient-script /usr/sbin/dhclient-scriptbak
service network restart

After the implementation of a face of muddled, EC2 into a brick, the link is broken, can not be linked.

开始修复

Begin to repair

修复思路: 将有问题磁盘挂载到一台正常能连接的ec2上,修复好后,再挂回来。 因这台ec2机器,上挂了两个磁盘,分别是 /dev/xvda(root device)和 /dev/sdb.

  1. 制作 /dev/xvda snapshot.
  2. 从snapshot创建volume.
  3. 将 volume 挂载到正常的 ec2 机器上 /dev/sdf1.
  4. 执行命令
代码语言:javascript
复制
mkdir /fix
mount /dev/sdf1 /fix
mv /fix/usr/sbin/dhclient-scriptbak /usr/sbin/dhclient-script
umount /dev/sdf1
  1. 在aws上将volume从正常的ec2 detach.
  2. 关机故障机器,卸载/dev/xvda.
  3. 将修复的volume重新挂载回故障ec2的root分区.分区路径 /dev/xvda
  4. 启动故障机器,完成修复.

repair idea: mounts the defective disk to a normally connected EC2, fixes it, and then mounts it back. has two disks mounted on this EC2 machine, /dev/xvda(root device) and /dev/sdb.

  1. Make /dev/xvda snapshot.
  2. Create volume from snapshot
  3. Mount the volume on /dev/sdf1 on a normal EC2 machine.
  4. Follow orders
代码语言:javascript
复制
mkdir /fix
mount /dev/sdf1 /fix
mv /fix/usr/sbin/dhclient-scriptbak /usr/sbin/dhclient-script
umount /dev/sdf1
  1. Remove the volume from normal EC2 detach on AWS.
  2. Shutdown the failed machine and uninstall /dev/xvda.
  3. Re-mount the repaired volume back into the root partition of the failed EC2. Partition path /dev/xvda
  4. Start the faulty machine and complete the repair.

dhclient-script 介绍

DHCP客户端的网络配置脚本不时地被dhclient调用。这个脚本被dhcp客户端用来在请求地址前设置每个接口的初始配置,在地址被提供后进行测试,并在获得租约后设置接口的最终配置。这个脚本并不意味着可以由终端用户进行定制。如果需要进行本地定制,应该可以使用所提供的输入和输出钩子。这些钩子将允许用户在创建/etc/resolv.conf文件时覆盖客户端的默认行为。当它启动时,客户端脚本首先定义了一个shell函数,make_resolv_conf,它随后被用来创建/etc/resolv.conf文件。要推翻默认行为,请在进入钩子脚本中重新定义这个函数。

dhclient-script Introduction

The DHCP client network configuration script is invoked from time to time by dhclient. This script is used by the dhcp client to set each interface’s initial configuration prior to requesting an address, to test the address once it has been offered, and to set the interface’s final configuration once a lease has been acquired. This script is not meant to be customized by the end user. If local customizations are needed, they should be possible using the enter and exit hooks provided. These hooks will allow the user to override the default behavior of the client in creating a /etc/resolv.conf file. When it starts, the client script first defines a shell function, make_resolv_conf, which is later used to create the /etc/resolv.conf file. To override the default behavior, redefine this function in the enter hook script. 个人博客: https://www.bthlt.com