[TOC]
## 获取主机IP地址
> 适用Centos7
`IPADDR=$(ip route show | grep -v default | awk '{print $9}')`
## 开启默认网卡并设置开机自启
> 适用Centos7
```
interface=$(ls /sys/class/net| grep -v "lo" | head -1)
ipaddr=$(ip route show | grep -v default | awk '{print $9}')
ifup $interface
sed -i "s/^ONBOOT=no/ONBOOT=yes/g" /etc/sysconfig/network-scripts/ifcfg-${interface}
```
## 获取局域网可用IP资源
准备文件get_ip.sh,在当前目录生成enable_ip
### get_ip.sh内容
```
#!/bin/bash
#获取可用IP
s1=$1
s2=$2
sed -i d enable_ip
for i in `seq ${s1} ${s2}`
do
ping 192.168.0.$i -c 3 2>&1 > /dev/null
[ $? -eq 1 ] && echo "192.168.0.$i" >> enable_ip
done
```
### 使用方法
1. 生成可用IP记录文件
```
./get_ip.sh 10 15
```
2. 获取可用IP
```
DOCKER_IP1=`cat enable_ip | head -1`
DOCKER_IP2=`cat enable_ip | head -2 | tail -1`
DOCKER_IP3=`cat enable_ip | head -3 | tail -1`
```
##