溫馨提示×

Debian ifconfig命令在腳本中的應用

小樊
46
2025-06-28 22:50:39
欄目: 智能運維

ifconfig 命令在 Debian 系統中用于配置、激活和查詢網絡接口的參數

  1. 獲取所有活動網絡接口的信息:
#!/bin/bash
interfaces=$(ifconfig -a | grep -o '^[^ ]\+')
for interface in $interfaces; do
    echo "Interface: $interface"
    ifconfig $interface
    echo ""
done
  1. 為指定網絡接口分配 IP 地址:
#!/bin/bash
interface="eth0"
ip_address="192.168.1.100"
netmask="255.255.255.0"

ifconfig $interface $ip_address netmask $netmask
  1. 關閉指定網絡接口:
#!/bin/bash
interface="eth0"

ifconfig $interface down
  1. 啟用指定網絡接口:
#!/bin/bash
interface="eth0"

ifconfig $interface up
  1. 刪除指定網絡接口的 IP 地址:
#!/bin/bash
interface="eth0"
ip_address="192.168.1.100"

ifconfig $interface del $ip_address

請注意,ifconfig 命令在某些 Debian 版本中可能已被棄用,建議使用 ip 命令替代。上述腳本可以根據需要進行相應的修改。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女