diff --git a/scripts/clash.sh b/scripts/clash.sh index 61c6c11..d8364a6 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -670,6 +670,7 @@ clashadv(){ echo -e " 4 启用小闪存模式: \033[36m$mini_clash\033[0m ————启动时方下载核心及数据库文件" echo -e " 5 配置内置DNS服务: \033[36m$dns_no\033[0m" echo -e " 6 手动指定clash运行端口及秘钥" + echo -e " 7 使用自定义配置" echo ----------------------------------------------- echo -e " 8 \033[31m重置\033[0m配置文件" echo -e " 9 \033[32m重启\033[0mclash服务" @@ -770,7 +771,34 @@ clashadv(){ elif [ "$num" = 6 ]; then setport clashadv - + + elif [ "$num" = 7 ]; then + [ ! -f $clashdir/user.yaml ] && cat > $clashdir/user.yaml < $clashdir/rules.yaml < " res if [ "$res" = "1" ];then diff --git a/scripts/rules(自定义规则示例文件请更名为rules.yaml).yaml b/scripts/rules(自定义规则示例文件请更名为rules.yaml).yaml deleted file mode 100644 index fce3ce4..0000000 --- a/scripts/rules(自定义规则示例文件请更名为rules.yaml).yaml +++ /dev/null @@ -1,11 +0,0 @@ -#用于编写自定义规则(此处规则将优先生效),(可参考https://lancellc.gitbook.io/clash/clash-config-file/rules): -#例如“🚀 节点选择”、“🎯 全球直连”这样的自定义规则组必须与config.yaml中的代理规则组相匹配,否则将无法运行! -# - DOMAIN-SUFFIX,google.com,🚀 节点选择 -# - DOMAIN-KEYWORD,baidu,🎯 全球直连 -# - DOMAIN,ad.com,REJECT -# - SRC-IP-CIDR,192.168.1.201/32,DIRECT -# - IP-CIDR,127.0.0.0/8,DIRECT -# - IP-CIDR6,2620:0:2d0:200::7/32,🚀 节点选择 -# - DST-PORT,80,DIRECT -# - SRC-PORT,7777,DIRECT - \ No newline at end of file diff --git a/scripts/start.sh b/scripts/start.sh index 7fc07a8..6605aaf 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -208,7 +208,6 @@ modify_yaml(){ else dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, nameserver: ['$dns_nameserver$dns_local'], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}' fi -################################### #设置目录 yaml=$clashdir/config.yaml tmpdir=/tmp/clash_$USER @@ -221,6 +220,7 @@ modify_yaml(){ #跳过本地tls证书验证 [ "$skip_cert" = "已开启" ] && sed -i '10,99s/skip-cert-verify: false/skip-cert-verify: true/' $tmpdir/proxy.yaml #添加配置 +################################### cat > $tmpdir/set.yaml <&1|grep -o 'Chain') - if [ -n "ip6_nat" -a "$ipv6_support" = "已开启" ];then + ip6_nat=$(ip6tables -t nat -L 2>&1 | grep -o 'Chain') + if [ -n "$ip6_nat" -a "$ipv6_support" = "已开启" ];then ip6tables -t nat -N clashv6 if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then #mac白名单 @@ -326,8 +327,8 @@ start_dns(){ iptables -t nat -I PREROUTING -p tcp -d 8.8.8.8 -j clash_dns iptables -t nat -I PREROUTING -p tcp -d 8.8.4.4 -j clash_dns #ipv6DNS - ip6_nat=$(ip6tables -t nat -L 2>&1|grep -o 'Chain') - if [ -n "ip6_nat" ];then + ip6_nat=$(ip6tables -t nat -L 2>&1 | grep -o 'Chain') + if [ -n "$ip6_nat" ];then ip6tables -t nat -N clashv6_dns > /dev/null 2>&1 if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then #mac白名单 @@ -361,7 +362,18 @@ start_udp(){ iptables -t mangle -A clash -d 192.168.0.0/16 -j RETURN iptables -t mangle -A clash -d 224.0.0.0/4 -j RETURN iptables -t mangle -A clash -d 240.0.0.0/4 -j RETURN - iptables -t mangle -A clash -p udp -j TPROXY --on-port $redir_port --tproxy-mark 1 + if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then + #mac白名单 + for mac in $(cat $clashdir/mac); do + iptables -t mangle -A clash -p udp -m mac --mac-source $mac -j TPROXY --on-port $redir_port --tproxy-mark 1 + done + else + #mac黑名单 + for mac in $(cat $clashdir/mac); do + iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN + done + iptables -t mangle -A clash -p udp -j TPROXY --on-port $redir_port --tproxy-mark 1 + fi iptables -t mangle -A PREROUTING -p udp -j clash } stop_iptables(){ diff --git a/scripts/user(自定义配置示例文件请更名为user.yaml).yaml b/scripts/user(自定义配置示例文件请更名为user.yaml).yaml deleted file mode 100644 index ff97dc9..0000000 --- a/scripts/user(自定义配置示例文件请更名为user.yaml).yaml +++ /dev/null @@ -1,5 +0,0 @@ -#用于编写自定义设定(可参考https://lancellc.gitbook.io/clash),例如 -#port: 7890 -#hosts: -# '*.clash.dev': 127.0.0.1 -# 'alpha.clash.dev': ::1