Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The case of Shell scripting uses regular expressions (network configuration and dhcp configuration scripts)

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Regular expressions are used in the case of Shell scripting

1) VMware software, virtual machine is Centos7 system, use shell script to configure static network card

#! / bin/bash# the shell script is suitable for the configuration of VMware Centos7 dual Nic # author:lokott#version:2.0# below is to disable the firewall and SELinux, which can not be written here I am used to shutting down systemctl stop firewalled.service & > / dev/nullsetenforce 0 & > / dev/nullcp-p / etc/sysconfig/network-scripts/ifcfg-ens33 / etc/sysconfig/network-scripts/ifcfg-ens36# before starting the service. The var=/etc/sysconfig/network-scripts#sed command changes dhcp to static, all ens33 to ens36, and deletes the line where UUID is located. Finally, add the subnet mask of the ip address and the default gateway, sed-I's _ If not, exit ipadd= `ifconfig ens36 directly | sed-n '2p' | awk' {print $2} '`if [$ipadd! = "192.168.100.100"] then exit 1fi

2) DHCP scripting

#! / bin/bash# this script is used to configure the shell script for the dhcp service # author:lokott#version:2.0# can be used to execute the script. / dhcp.sh 2 > & 1 > / dev/nullyum install dhcp- y & > / dev/nullyum install expect-y & > / dev/nullvar1=/usr/share/doc/dhcp-4.2.5/dhcpd.conf.examplevar2=/etc/dhcp/dhcpd.conf# below is to turn off the firewall and SELinux. You don't have to write here. I am used to shutting down systemctl stop firewalled.service & > / dev/nullsetenforce 0 & > / dev/null#expect interaction-free part / usr/bin/expect before starting the service.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report