라즈베리 파이에서는 dhcpcd.conf 파일의 고정 IP 설정을 변경할 수있는 간단한 스크립트를 작성하려고합니다. 아래 스크립트는 dns-servers를 제외하고 작동합니다. 공백으로 구분 된 두 개의 IP 주소가 포함되어 있기 때문에 sed 문은 해당 줄에서 작동하지 않는 것으로 보입니다. 스크립트는 다음과 같다 :sed를 사용하여 dhcpcd.conf 파일의 IP 주소 변경
정적 IP_ADDRESS = 192.168.126.7/24
정적 라우터 = 192.168.126.1
이 같은 dhcpcd.conf 파일보기에#!/bin/bash
currip=$(cat /etc/dhcpcd.conf | grep -e '^static ip_address=' | cut -d= -
f2)
currgw=$(cat /etc/dhcpcd.conf | grep -e '^static routers=' | cut -d= -f2)
currdns=$(cat /etc/dhcpcd.conf | grep -e '^static domain_name_servers=' |
cut -d= -f2)
echo "current IP is $currip"
echo "current GW is $currgw"
echo "current DNS servers are $currdns"
echo "Enter new static ip in form of x.x.x.x/x: "
read newip
echo "Enter new GW in form of x.x.x.x: "
read newgw
echo "Enter new DNS servers in form of x.x.x.x x.x.x.x: "
read newdns
echo "currip is $currip"
echo "new ip will be $newip"
echo "new dns will be $newdns"
sed -i -e "[email protected]$currip\[email protected][email protected]" /etc/dhcpcd.conf
sed -i -e "[email protected]$currgw\[email protected][email protected]" /etc/dhcpcd.conf
sed -i -e "[email protected]$currdns\[email protected][email protected]" /etc/dhcpcd.conf
chip=$(cat /etc/dhcpcd.conf | grep -e '^static ip_address=' | cut -d= -
f2)
chgw=$(cat /etc/dhcpcd.conf | grep -e '^static routers=' | cut -d= -f2)
chdns=$(cat /etc/dhcpcd.conf | grep -e '^static domain_name_servers=' |
cut -d= -f2)
echo "The ip has been changed to $chip"
echo "The GW has been changed to $chgw"
echo "The DNS server have been changed to $chdns"
의 선을
static domain_name_servers = 192.168.126.1 66.243.243.101
domain_name_servers에 대해 내 sed 문을 어떻게 조정해야합니까?
무엇이 문제입니까? 현재 스크립트는'192.168.126.1 66.243.243.101'을 입력 한 새로운 DNS로 바꿉니다. – janos