v2ray_ss_conf.sh 4.2 KB

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