v2ray_ss_conf.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/bin/bash
  2. v2ray_port=8000
  3. UUID=$(cat /proc/sys/kernel/random/uuid)
  4. serverip=$(curl -4 ip.sb)
  5. ss_port=40000
  6. cur_dir=$(pwd)
  7. # 修改端口号
  8. setport(){
  9. echo_SkyBlue ":: 1.请修改 V2ray 服务器端端口号,默认:${RedBG} ${v2ray_port} "
  10. read -p "请输入数字(100--60000): " num
  11. if [[ ${num} -ge 100 ]] && [[ ${num} -le 60000 ]]; then
  12. v2ray_port=$num
  13. fi
  14. echo_SkyBlue ":: 2.请修改 Shadowsocks 服务器端端口号,默认: ${RedBG} ${ss_port} "
  15. read -p "请输入数字(100--60000): " num
  16. if [[ ${num} -ge 100 ]] && [[ ${num} -le 60000 ]]; then
  17. ss_port=$num
  18. fi
  19. }
  20. conf_shadowsocks(){
  21. if [ ! -e '/etc/rc.local' ]; then
  22. bash <(curl -L -s https://git.io/wgmtu)
  23. fi
  24. old_ss_port=$(cat /etc/rc.local | grep ss-server | awk '{print $5}')
  25. ss_passwd=$(cat /etc/rc.local | grep ss-server | awk '{print $7}')
  26. sed -i "s/${old_ss_port}/${ss_port}/g" "/etc/rc.local"
  27. sed -i "s/ss-server -s 127.0.0.1/ss-server -s 0.0.0.0/g" "/etc/rc.local"
  28. systemctl restart rc-local
  29. # ss://<<base64_shadowsocks.conf>>
  30. echo "aes-256-gcm:${ss_passwd}@${serverip}:${ss_port}" | tee ${cur_dir}/base64_shadowsocks.conf
  31. }
  32. conf_v2ray(){
  33. if [ ! -e '/etc/v2ray/config.json' ]; then
  34. bash <(curl -L -s https://install.direct/go.sh)
  35. fi
  36. # vmess://<<base64_v2ray_vmess.json>>
  37. cat <<EOF | tee ${cur_dir}/base64_v2ray_vmess.json
  38. {
  39. "v": "2",
  40. "ps": "v2ray",
  41. "add": "${serverip}",
  42. "port": "${v2ray_port}",
  43. "id": "${UUID}",
  44. "aid": "64",
  45. "net": "kcp",
  46. "type": "srtp",
  47. "host": "",
  48. "path": "",
  49. "tls": ""
  50. }
  51. EOF
  52. # v2ray服务端mKcp配 /etc/v2ray/config.json
  53. cat <<EOF >/etc/v2ray/config.json
  54. {
  55. "inbounds": [
  56. {
  57. "port": $v2ray_port,
  58. "protocol": "vmess",
  59. "settings": {
  60. "clients": [
  61. {
  62. "id": "${UUID}",
  63. "level": 1,
  64. "alterId": 64
  65. }
  66. ]
  67. },
  68. "streamSettings": {
  69. "tcpSettings": {},
  70. "quicSettings": {},
  71. "tlsSettings": {},
  72. "network": "kcp",
  73. "kcpSettings": {
  74. "mtu": 1350,
  75. "tti": 50,
  76. "header": {
  77. "type": "srtp"
  78. },
  79. "readBufferSize": 2,
  80. "writeBufferSize": 2,
  81. "downlinkCapacity": 100,
  82. "congestion": false,
  83. "uplinkCapacity": 100
  84. },
  85. "wsSettings": {},
  86. "httpSettings": {},
  87. "security": "none"
  88. }
  89. }
  90. ],
  91. "log": {
  92. "access": "/var/log/v2ray/access.log",
  93. "loglevel": "info",
  94. "error": "/var/log/v2ray/error.log"
  95. },
  96. "routing": {
  97. "rules": [
  98. {
  99. "ip": [
  100. "0.0.0.0/8",
  101. "10.0.0.0/8",
  102. "100.64.0.0/10",
  103. "169.254.0.0/16",
  104. "172.16.0.0/12",
  105. "192.0.0.0/24",
  106. "192.0.2.0/24",
  107. "192.168.0.0/16",
  108. "198.18.0.0/15",
  109. "198.51.100.0/24",
  110. "203.0.113.0/24",
  111. "::1/128",
  112. "fc00::/7",
  113. "fe80::/10"
  114. ],
  115. "type": "field",
  116. "outboundTag": "blocked"
  117. }
  118. ]
  119. },
  120. "outbounds": [
  121. {
  122. "protocol": "freedom",
  123. "settings": {}
  124. },
  125. {
  126. "protocol": "blackhole",
  127. "tag": "blocked",
  128. "settings": {}
  129. }
  130. ]
  131. }
  132. EOF
  133. systemctl restart v2ray
  134. }
  135. # 定义文字颜色
  136. Green="\033[32m" && Red="\033[31m" && GreenBG="\033[42;37m" && RedBG="\033[41;37m"
  137. Font="\033[0m" && Yellow="\033[0;33m" && SkyBlue="\033[0;36m"
  138. echo_SkyBlue(){
  139. echo -e "${SkyBlue}$1${Font}"
  140. }
  141. echo_Yellow(){
  142. echo -e "${Yellow}$1${Font}"
  143. }
  144. # 显示手机客户端二维码
  145. conf_QRcode(){
  146. # 安装二维码插件
  147. if [ ! -e '/usr/bin/qrencode' ]; then
  148. apt -y install qrencode
  149. fi
  150. if [ ! -e '/usr/bin/qrencode' ]; then
  151. yum -y install qrencode
  152. fi
  153. ss_b64=$(base64 ${cur_dir}/base64_shadowsocks.conf)
  154. shadowsocks_ss="ss://${ss_b64}"
  155. v2_b64=$(base64 ${cur_dir}/base64_v2ray_vmess.json)
  156. v2ray_vmess="vmess://${v2_b64}"
  157. echo_SkyBlue ":: Shadowsocks 服务器二维码,请手机扫描!"
  158. echo $shadowsocks_ss | qrencode -o - -t UTF8
  159. echo_Yellow $shadowsocks_ss
  160. echo
  161. echo_SkyBlue ":: V2rayNG 手机配置二维码,请手机扫描!"
  162. echo $v2ray_vmess | tr -d " " | qrencode -o - -t UTF8
  163. echo_Yellow ":: V2rayN Windows 客户端 Vmess 协议配置"
  164. echo $v2ray_vmess | tr -d " "
  165. }
  166. clear
  167. if [ ! -e 'base64_v2ray_vmess.json' ]; then
  168. echo_SkyBlue ":: Shadowsocks 和 V2Ray 简易配置: 生成和显示二维码 By 蘭雅sRGB "
  169. echo_Yellow ":: 首次配置保存文件 base64_v2ray_vmess.json, 如再次配置请先手工删除!"
  170. setport
  171. conf_shadowsocks
  172. conf_v2ray
  173. fi
  174. # 输出ss和v2ray配置和二维码
  175. conf_QRcode