m (Protected "Shell Scripting : IP Address Debian" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) [cascading])
No edit summary
Line 1: Line 1:
Membuat shell script untuk konfigurasi IP Address di Debian
Buat file baru<syntaxhighlight lang="linuxconfig">
nano konfig_ipaddress.sh
</syntaxhighlight>isi script nya seperti beikut ini :<syntaxhighlight lang="linuxconfig" line="1">
#!/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!"
</syntaxhighlight>berikan izin untuk file di atas.<syntaxhighlight lang="linuxconfig">
chmod +x konfig_ipaddress.sh
</syntaxhighlight>

Revision as of 20:15, 7 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