kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

docker 设置固定IP

1 设置固定IP

使用默认的网络是不支持指派固定IP的

1
2
3
4
5
6
# 创建自定义网络
docker network create --subnet=192.168.3.0/24 --gateway=192.168.3.1 nett
docker network ls

#
docker run -i -t --net nett --ip 192.168.3.2 49f7960eb7e4 /bin/bash

2 修改bridge

1
2
3
4
5
6
7
8
9
10
brctl addbr br1
brctl show

vim /etc/sysconfig/docker
ifconfig br1 100.64.0.1 netmask 255.255.255.0

vim /etc/sysconfig/docker-network
DOCKER_NETWORK_OPTIONS="-b=br1"

service docker restart

或者配置docker

3 pipework配置docker网络

pipework-master.zip

1
2
3
4
5
6
git clone https://github.com/jpetazzo/pipework.git
sudo cp pipework/pipework /usr/local/bin/

docker run -itd --name d1 --net=none centos2 /bin/bash
pipework br1 d1 100.64.0.100/24@100.64.0.1
docker exec -it d1 /bin/bash

4 修改本机为bridge, docker分配同本机网段

vim /etc/sysconfig/network-scripts/ifcfg-enp0s3

1
增加 BRIDGE="br0"

vim /etc/sysconfig/network-scripts/ifcfg-br0

1
2
3
4
DEVICE="br0"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO=dhcp

service network restart

1
2
3
4
5
6
7
8
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/enp0s3/proxy_arp

docker run -itd --name d2 --net=none centos2 /bin/bash
pipework br0 d2 192.168.43.189/24@192.168.43.1
brctl show

docker exec -it d2 /bin/bash

system, docker

« docker的四种网络模式 Linux 上的抽象网络设备 »