Skip to content

Improve DHCP support #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ GS_CIDR="24" # Define your CIDR
GS_NETBR="vmbr0" # Define network bridge (default: vmbr0)
GS_DNS00="1.1.1.1" # Default DNS resolver
GS_DNS01="8.8.8.8" # Default secondary DNS resolver
GS_OVERRIDE_DNS_FROM_DHCP="0" # Override DNS settings when you use DHCP server (value: 0|1)

#######################################################################################################################################
# CLOUD-INIT GUESTS SETTINGS
Expand Down
4 changes: 3 additions & 1 deletion src/chk_mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ chk_args(){
exit 1
fi
elif [ "$1" == "iplist" ]; then # syntax of list ip adresse like 192.168.2.XX,XX.XX
if ! [[ $3 =~ ^(([0-9]{1,3}\.){3}[0-9]{1,3}(,[0-9]{1,3})*$)|^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
if ! [[ $3 == "dhcp" ]]; then
if ! [[ $3 =~ ^(([0-9]{1,3}\.){3}[0-9]{1,3}(,[0-9]{1,3})*$)|^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
msg_error "Argument: '$3' for IP list does not follow the required nomenclature"
exit 1
fi
fi
elif [ "$1" == "vmid" ]; then # syntax of list vmimd like 100,101,102,103
IFS=',' read -ra nums <<< "$3"
Expand Down
10 changes: 7 additions & 3 deletions src/make_mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ guest_qm_ipconfig(){
#### IP attribution
if [ "$GS_NETCONF" == "dhcp" ]; then
qm set "$key" --ipconfig"$QS_NET_ETH" ip=dhcp >/dev/null
qm set "$key" --nameserver "$GS_DNS00 $GS_DNS01" >/dev/null
if [ "$GS_OVERRIDE_DNS_FROM_DHCP" = "1" ]; then
qm set "$key" --nameserver "$GS_DNS00 $GS_DNS01" >/dev/null
fi
# TODO qm set "$key" --searchdomain "local" >/dev/null
else
qm set "$key" --ipconfig"$QS_NET_ETH" ip="${slug_serv[$key]}/$GS_CIDR,gw=$GS_GATE" >/dev/null
Expand Down Expand Up @@ -271,8 +273,10 @@ guest_lxc_ipconfig(){
#### IP attribution
if [ "$GS_NETCONF" == "dhcp" ]; then
pct set "$key" --net"$CS_NET_ETH" \
name="$CS_NET_NAME""$CS_NET_ETH",ip=dhcp,bridge="$GS_NETBR",gw="$GS_GATE" >/dev/null
pct set "$key" --nameserver "$GS_DNS00 $GS_DNS01" >/dev/null
name="$CS_NET_NAME""$CS_NET_ETH",ip=dhcp,bridge="$GS_NETBR" >/dev/null
if [ "$GS_OVERRIDE_DNS_FROM_DHCP" = "1" ]; then
qm set "$key" --nameserver "$GS_DNS00 $GS_DNS01" >/dev/null
fi
# pct set "$key" --searchdomain "local" >/dev/null
else
pct set "$key" --net"$CS_NET_ETH" \
Expand Down
24 changes: 20 additions & 4 deletions src/set_mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ display_shape(){
msg_info_inline "Network"
msg_syntax_nb " (device_type:'$QS_NET0', interface:'$QS_NET_ETH', bridge_set:'$GS_NETBR')"
msg_info_inline "Network values"
msg_syntax_nb " (gateway:'$GS_GATE', attribute_ip:'$GS_NETCONF', cidr:'$GS_CIDR')"
if [[ "$GS_NETCONF" == "dhcp" ]]; then
msg_syntax_nb " (attribute_ip:'$GS_NETCONF')"
else
msg_syntax_nb " (gateway:'$GS_GATE', attribute_ip:'$GS_NETCONF', cidr:'$GS_CIDR')"
fi
msg_info_inline "DNS/Search domain"
msg_syntax_nb " (DNS00:'$GS_DNS00', DNS01:'$GS_DNS01')"
if [[ "$GS_NETCONF" == "dhcp" ]] && [[ "$GS_OVERRIDE_DNS_FROM_DHCP" == "0" ]]; then
msg_syntax_nb " (DNS: 'use dhcp')"
else
msg_syntax_nb " (DNS00:'$GS_DNS00', DNS01:'$GS_DNS01')"
fi
msg_info_inline "Start on boot"
msg_syntax_nb " (value:'$QS_ONBOOT')"
msg_info_inline "Start immediatly after creation"
Expand All @@ -88,9 +96,17 @@ display_shape(){
msg_info_inline "Network"
msg_syntax_nb " (device_name:'$CS_NET_NAME', interface:'$CS_NET_ETH', bridge_set:'$GS_NETBR')"
msg_info_inline "Network values"
msg_syntax_nb " (gateway:'$GS_GATE', attribute_ip:'$GS_NETCONF', cidr:'$GS_CIDR')"
if [[ "$GS_NETCONF" == "dhcp" ]]; then
msg_syntax_nb " (attribute_ip:'$GS_NETCONF')"
else
msg_syntax_nb " (gateway:'$GS_GATE', attribute_ip:'$GS_NETCONF', cidr:'$GS_CIDR')"
fi
msg_info_inline "DNS/Search domain"
msg_syntax_nb " (DNS00:'$GS_DNS00', DNS01:'$GS_DNS01')"
if [[ "$GS_NETCONF" == "dhcp" ]] && [[ "$GS_OVERRIDE_DNS_FROM_DHCP" == "0" ]]; then
msg_syntax_nb " (DNS: 'use dhcp')"
else
msg_syntax_nb " (DNS00:'$GS_DNS00', DNS01:'$GS_DNS01')"
fi
msg_info_inline "Start on boot"
msg_syntax_nb " (value:'$CS_ONBOOT')"
msg_info_inline "Start immediatly after creation"
Expand Down