【更新】请教一个关于命令行修改IP的问题
Tofloor
poster avatar
zwq133
deepin
2016-10-27 04:46
Author
本帖最后由 zwq133 于 2016-10-27 05:16 编辑

更新一下:

自己写实在没那技能,于是在网上淘了一个下面的shell脚本:
  1. #!/bin/bash
  2. ############################配置IP脚本#####################################
  3. fun0 () {
  4.         ipfile="/etc/sysconfig/network-scripts/ifcfg-eth0"
  5.         hwaddr=`ifconfig |grep enp2s0 |awk -F " " '{print $5}'`
  6.         device=`ifconfig |grep enp2s0 |awk -F " " '{print $1}'`
  7.         type=`ifconfig |grep enp2s0 |awk -F ":" '{ print $2 }'|awk -F " " '{
  8. print $1 }'`
  9.         echo "DEVICE=$device" > $ipfile
  10.         echo "HWADDR=$hwaddr" >>$ipfile
  11.         echo "ONBOOT=yes" >>$ipfile
  12.         echo "TYPE=$type" >>$ipfile
  13. }

  14. fun1 () {
  15.          echo "输入你想设置的IP:"
  16.         read IP
  17.         echo "输入子网掩码:"
  18.         read netmask
  19.         echo "输入默认网关:"
  20.         read gateway
  21.         echo "输入DNS:"
  22.         read dns
  23. }
  24. echo "输入你想要设置的IP类型 (DHCP/STATIC):"
  25. read model
  26. if [ $model = "DHCP" ]
  27. then
  28.         fun0
  29.         echo "BOOTPROTO=dhcp" >>$ipfile
  30.         service network restart
  31. elif [ $model = "STATIC" ]
  32. then
  33.         fun1
  34.         fun0
  35.         echo "BOOTPROTO=none" >>$ipfile
  36.         echo "子网掩码=$netmask" >>$ipfile
  37.         echo "IP地址 =$IP" >>$ipfile
  38.         echo "默认网关=$gateway" >>$ipfile
  39.         echo "$dns" > /etc/resolv.conf
  40.         service network restart

  41. else
  42.         echo "错误:请输入 DHCP or STATIC"
  43.         exit 0
  44. fi
Copy the Code


顺便再问一下deepin的网卡配置文件在哪,按照网上搜索和WIKI上的说法是“/etc/sysconfig/network-scripts/ifcfg-eth0”,但是现在的deepin找不到这个文件了,那么替代的文件在哪里呢?
Reply Favorite View the author
All Replies
avatar
android
deepin
2016-10-27 04:59
#1
read -p 'IP地址,默认【192.168.1.100】: ' ip
ip=192.168.1.100
这个调换下
下面的类似
Reply View the author
avatar
zwq133
deepin
2016-10-27 05:28
#2
https://bbs.deepin.org/post/44940
read -p 'IP地址,默认【192.168.1.100】: ' ip
ip=192.168.1.100
这个调换下

额,恕我愚昧,表示没有看懂~~~能讲仔细点么!
Reply View the author
avatar
hwang
deepin
2016-10-27 06:02
#3
就是说你把这两条语句调换个位置就行了,你检查看看就明白了
Reply View the author