建立专有网络后, 在一台 「头脑机」如 10.0.0.1 上准备好模板文件(例x.tgz), 搭建 http 服务和 dns 服务, 参考 nginx 和 dnsmasq.
x.tgz 的作用:
在控制台申请机器时, 用户自定义数据如下
#!/bin/sh cd / curl 10.0.0.1/x.tgz | tar xz echo ' DNS1=10.0.0.1 DNS2=10.0.0.1 ' >>/etc/sysconfig/network-scripts/ifcfg-eth0 adduser q && yes qw | passwd q && usermod -a -G wheel q systemctl disable tuned yum install -y dstat htop lsof nc openssh reboot
or
#!/bin/sh cd / curl 10.0.0.1/x.tgz | tar xz curl 10.0.0.1/init.sh | sh reboot
我们为了方便, 直接用专有网络自动分配的地址(dhcp), 因为 ip 地址的分配顺序是可预见的, 所以还算可控.
连续设置 DNS1 DNS2 是为了避免默认 dns 的干扰.
x.tgz 例子:
tar xf x.tgz tail $(find etc/ root/ -type f) ==> etc/hostname <== ==> etc/hosts <== 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost6 localhost6.localdomain6 ==> etc/ssh/sshd_config <== Port 65522 UseDNS no AddressFamily inet PermitRootLogin without-password SyslogFacility AUTHPRIV GatewayPorts clientspecified ClientAliveInterval 60 ClientAliveCountMax 3 ==> root/.ssh/authorized_keys <== ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDHWrD5V10X9SWTYnfIGQcglQmjiCK6KyMDKyTgwb3Vx+Dfpa5EiRFerAKzxM+IiL8lQmUVKzoRk5rl36iQMRCcN5QNQJCtuhJSos94OMWotfvspIqhIuRig8S7CI7SNgvPRkzup8a/J78EQAr40ukjKRlQzJkuWtD22RhqdpPZRrF/JNE+8m/+sHt0UyVJ3GD0dcBDO7vrfGukjSZ3XqM+CDi/5xBgOOG0PR3K0VWQjtuqQoJbkFBGAFwZqTFk32nF7RzE+JyyUE0TPnfrNaNBCFJQcr9jr5icaGgEY7J5R2B55FwwDAPK6qfJ1P4srEm9zcL1g3LtZjMwIm2hx9a1 tc@box ==> root/.inputrc <== "\C-p": history-search-backward "\C-n": history-search-forward
有时,我们买的机器没有公网IP,就无法直接访问互联网,这时,应该用 NAT。可以买服务,但是贵,还是自建比较好。 参考 https://www.cnblogs.com/EasonJim/p/10206743.html 。
例子:
ECS-1 10.0.0.91 有公网IP
ECS-2 10.0.0.92
ECS-3 10.0.0.93
ECS-1:
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf sysctl -p iptables -t nat -I POSTROUTING -s 10.0.0.0/24 -j SNAT --to-source 10.0.0.91
ECS-2 等其他主机不用做特殊操作,然后去专有网络里面配置路由表,管理->添加路由表:
0.0.0.0/0
下一跳选择ECS实例,选 ECS-1。然后其他机器就可以上网了。
#systemctl stop aliyun #/etc/init.d/aegis uninstall systemctl disable AssistDaemon aliyun aegis