Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way to move Rewrite Roules out of file? On one side sendmail documentation recommends doing changes only in file, but all Rewrite Rules are in .cf file. I suppose that all changes to Rewrite Rules in .cf file will be lost during next .cf file generation from .mc.

share|improve this question
up vote 1 down vote accepted

Mostly and rewriting rules are considered so geeky and arcane that very few people fiddle with them; the whole mechanism provides a more "user-friendly" front end to sendmail configuration. Most folks should stick exclusively to the mechanism and never directly modify -including producing modified rewrite rules- at all.

If the mechanism won't quite work for you and you want to "tweak" a few rules in, you may be able to do it with the LOCAL_NET_CONFIG and LOCAL_RULESETS capabilities of the mechanism. If you want to make major mods directly to, maybe even dispensing with the mechanism altogether, you're beyond what 99.44% of admins need to do, and may need some custom editing of Makefiles and/or shell scripts to implement your desired scheme. (Beware that on some systems service sendmail start will invoke the Makefile which executes the mechanism, so overwriting of will occur more often than you may expect.)

(To be brutally honest, I too sometimes find having this two-level indirect sort of front end interface a little awkward and frustrating: sometimes I know what I want, and I know how to make do it ...but I can't figure out the "right" way to say it with the mechanism. And advice for different versions of BIND is sometimes more misleading than helpful. What often works for me is using a few words from the desired in a grep command to turn up the "right" feature: grep "desired_sendmail.cf_words" /usr/share/*/*.)

Per the sendmail README (perhaps /usr/share/sendmail-cf/README) you can cause the M4> mechanism to insert arbitrary additional rewrite rules literally by specifying LOCAL_NET_CONFIG and/or LOCAL_RULESET (and LOCAL_RULE_3, LOCAL_RULE_0, LOCAL_RULE_1, and LOCAL_RULE_2) in For example, to insert a delivery rewrite rule:

# Add/insert my own additional rewrite-rule(s)
R$* < @ $* .$m. > $*    $#smtp $@ $2.$m. $: $1 < @ $2.$m. > $3

or to add a new rewrite-ruleset:

# Add one or more new rewrite-rulesets (subroutines) [new name]
R$*     $: $&{auth_authen}
Rsmmsp  $# OK

or to append more rewrite-rules to the end of an existing rewrite-ruleset:

# Append to one or more existing rewrite-rulesets (subroutines) [existing name]
R$*     $: $&{auth_authen}
Rsmmsp  $# OK

However, this mechanism is for "tweaking" the existing rewrite-rule framework but not for making completely arbitrary changes to rewrite-rules. Rules using LOCAL_NET_CONFIG will always be inserted at the same place: halfway through ruleset 0. And they can't be wildly different from what was there before such that delivery no longer approximately matches the assumptions made by the existing "parse" functionality. New rulesets (subroutines) from LOCAL_RULESETS will either be called only by your inserted rules, or be called directly by the sendmail program itself depending on specific (and possibly obscure) subroutine names and FEATURE specifications. And extensions to existing rulesets (subroutines) from LOCAL_RULESET can add new functionality, but probably cannot change existing functionality, as a match and "return" by an existing earlier rule will terminate execution of that ruleset before your additional rules are even reached. Nevertheless, this may be adequate for what you want.

If you do this, use the sendmail -bt -Ctrial_sendmail.cf_file -d21.15 test mechanism to make sure it's behaving the way you intend. Remember, your "style" should be to compose your new rules in such a way that they fit seamlessly into the existing ruleset framework (rather than making arbitrary changes with little consideration for the existing framework); it's rather like adding a new feature to existing code that was structured by somebody else. The distributed rewrite rules are very good at handling not only mainline behavior but also edge cases (MX for individual hosts? Masquerade exceptions? UUCP connectivity? aliases? etc.?); hopefully your added rules will be similarly comprehensive.

share|improve this answer

sendmail when run reads So must exist and contain the full set of rules and variables that need to be set to match your requirements for a working setup. The most common way to build is by maintaining the simpler file and then using m4 to "compile" into So yes, it is possible to break the file into parts and then by carefully executing m4 to produce the (single)

I highly recommend the bat book if you want to tinker with and .cf. For an approach that bypasses m4 and you can look at Sendmail Theory and Practice but it may be overkill for most people.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.