Shell Scripting : IP Address Debian: Difference between revisions
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[File:ShellScripting.png|thumb|'''ShellScripting''']] | |||
Buat file baru<syntaxhighlight lang="linuxconfig"> | Buat file baru<syntaxhighlight lang="linuxconfig"> | ||
nano konfig_ipaddress.sh | nano konfig_ipaddress.sh | ||
Line 83: | Line 84: | ||
</syntaxhighlight>berikan izin untuk file di atas.<syntaxhighlight lang="linuxconfig"> | </syntaxhighlight>berikan izin untuk file di atas.<syntaxhighlight lang="linuxconfig"> | ||
chmod +x konfig_ipaddress.sh | chmod +x konfig_ipaddress.sh | ||
</syntaxhighlight> | |||
Jalankan dengan mengetikkan perintah berikut<syntaxhighlight lang="linuxconfig"> | |||
./konfig_ipaddress.sh | |||
</syntaxhighlight>Jika tidak script tidak mau jalan, jalankan terlebih dahulu perintah berikut ini<syntaxhighlight lang="linuxconfig"> | |||
sed -i 's/\r$//' konfig_ipaddress.sh | |||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 18:23, 8 October 2025

Buat file baru
nano konfig_ipaddress.sh
isi script nya seperti beikut ini :
#!/bin/bash
# Script konfigurasi IP address static di Debian 12
echo "=== Konfigurasi IP Address Debian 12 ==="
# Cek interface yang available
echo "Network interfaces yang tersedia:"
ip link show | grep "^[0-9]" | awk -F: '{print $2}'
echo ""
read -p "Masukkan nama interface (contoh: ens33, eth0): " INTERFACE
read -p "Masukkan IP address (contoh: 192.168.1.100): " IP_ADDRESS
read -p "Masukkan netmask (contoh: 255.255.255.0): " NETMASK
read -p "Masukkan gateway (contoh: 192.168.1.1): " GATEWAY
read -p "Masukkan DNS (contoh: 8.8.8.8): " DNS_SERVER
echo ""
echo "Summary konfigurasi:"
echo "Interface: $INTERFACE"
echo "IP Address: $IP_ADDRESS"
echo "Netmask: $NETMASK"
echo "Gateway: $GATEWAY"
echo "DNS: $DNS_SERVER"
read -p "Lanjutkan konfigurasi? (y/n): " CONFIRM
if [ "$CONFIRM" != "y" ]; then
echo "Konfigurasi dibatalkan"
exit 1
fi
# Backup config original dulu
echo "Backup config original..."
cp /etc/network/interfaces /etc/network/interfaces.backup.$(date +%Y%m%d_%H%M%S)
# Buat config baru
cat > /etc/network/interfaces << EOF
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto $INTERFACE
iface $INTERFACE inet static
address $IP_ADDRESS
netmask $NETMASK
gateway $GATEWAY
dns-nameservers $DNS_SERVER
EOF
echo "✅ Config file berhasil dibuat!"
# Restart networking service
echo "Restarting network service..."
systemctl restart networking
if [ $? -eq 0 ]; then
echo "✅ Network service restarted successfully"
else
echo "⚠️ Coba restart manual: systemctl restart networking"
fi
# Test koneksi
echo ""
echo "Testing koneksi..."
ping -c 3 $GATEWAY
if [ $? -eq 0 ]; then
echo "✅ Koneksi ke gateway BERHASIL"
else
echo "❌ Koneksi ke gateway GAGAL"
fi
echo "Konfigurasi selesai!"
berikan izin untuk file di atas.
chmod +x konfig_ipaddress.sh
Jalankan dengan mengetikkan perintah berikut
./konfig_ipaddress.sh
Jika tidak script tidak mau jalan, jalankan terlebih dahulu perintah berikut ini
sed -i 's/\r$//' konfig_ipaddress.sh