Skip to main content

Rules

Egern supports multiple types of rules that can be used to control the proxy behavior of network traffic and to block certain traffic.

Supported Rules

TypeNameDescription
domainExact Domain MatchMatches the domain exactly
domain_keywordDomain Keyword MatchMatches domains containing the input keyword
domain_suffixDomain Suffix MatchMatches domains with the input suffix
domain_regexDomain Regex MatchMatches domains using regular expressions
geoipIP Country Code MatchMatches IP addresses based on country code
ip_cidrIPv4 Range MatchMatches specified IPv4 address ranges
ip_cidr6IPv6 Range MatchMatches specified IPv6 address ranges
url_regexURL Regex MatchMatches URLs using regular expressions
rule_setRule SetLocal or remote files
asnASN RuleMatches ASN codes or organizations
defaultDefault RuleApplied when other rules do not match
  • match: The value to match.
  • policy: The policy name, which determines how the matched traffic should be handled—such as a proxy server, policy group, direct connection, or rejection. If this value is DIRECT, the matched traffic will not use the proxy. If this value is REJECT, the matched traffic will be blocked. Note that the names of proxy servers and policy groups are applied here.
rules:
- domain:
match: www.google.com
policy: Proxy
- domain_keyword:
match: google
policy: Proxy
- domain_suffix:
match: google.com
policy: Proxy
- domain_regex:
match: google|gstatic|ytimg|youtube|ggpht
policy: Proxy
- geoip:
match: US
policy: Proxy
- ip_cidr:
match: 192.168.0.0/16
policy: DIRECT
- url_regex:
match: "https://www.google.com/"
policy: Proxy
- rule_set:
match: "./example.yaml"
policy: Proxy
- asn:
match: "1234"
policy: DIRECT
- default:
policy: DIRECT

In this example, we have set various types of rules. For instance, we use the domain rule to proxy traffic to www.google.com, the domain_keyword rule to proxy traffic to all domains containing google, and the geoip rule to proxy traffic from IP addresses in the United States, among others. The default rule is set to direct connection, meaning that when other rules do not match, traffic will connect directly without using the proxy.

Rule Sets

Rule sets can be local or remote files. They allow you to reuse or share rules across multiple configuration files.

TypeName
domain_setDomain Set
domain_keyword_setDomain Keyword Match Set
domain_suffix_setDomain Suffix Match Set
domain_regex_setDomain Regex Match Set
geoip_setIP Country Code Match Set
ip_cidr_setIPv4 Range Match Set
ip_cidr6_setIPv6 Range Match Set
url_regex_setURL Regex Match Set
asn_setASN Rule Set

Rule Set Examples

domain_set:
- www.google.com
- www.youtube.com
domain_keyword_set:
- google
- youtube
domain_suffix_set:
- google.com
- youtube.com
domain_regex_set:
- google|gstatic|ytimg|youtube|ggpht
geoip_set:
- US
- UK
ip_cidr_set:
- 192.168.0.0/16
url_regex_set:
- "https://www.google.com/"

In this example, we have set values for each type of rule set. For instance, our domain_set includes www.google.com and www.youtube.com, meaning that when we reference this rule set, traffic to these domains will be matched. Similarly, our geoip_set includes US and UK, so when we reference this rule set, traffic from IP addresses in the United States and the United Kingdom will be matched.